You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用CSharpMath.Forms 0.5.1时System.Numerics.Vectors版本冲突问题求解

解决CSharpMath 0.5.1的System.Numerics.Vectors版本冲突

问题描述

升级到CSharpMath 0.5.1后,编译项目时出现以下版本冲突警告,导致组件无法正常工作:

Warning     Found conflicts between different versions of "System.Numerics.Vectors" that could not be resolved.
There was a conflict between "System.Numerics.Vectors, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "System.Numerics.Vectors, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
    "System.Numerics.Vectors, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was chosen because it was primary and "System.Numerics.Vectors, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was not.
    References which depend on "System.Numerics.Vectors, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" [C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\System.Numerics.Vectors.dll].
        C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\System.Numerics.Vectors.dll
          Project file item includes which caused reference "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\System.Numerics.Vectors.dll".
            System.Numerics.Vectors
    References which depend on "System.Numerics.Vectors, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" [].
        C:\Users\vizid\.nuget\packages\csharpmath.rendering\0.5.1\lib\netstandard2.0\CSharpMath.Rendering.dll
          Project file item includes which caused reference "C:\Users\vizid\.nuget\packages\csharpmath.rendering\0.5.1\lib\netstandard2.0\CSharpMath.Rendering.dll".
            C:\Users\vizid\.nuget\packages\csharpmath.rendering\0.5.1\lib\netstandard2.0\CSharpMath.Rendering.dll
            C:\Users\vizid\.nuget\packages\csharpmath.forms\0.5.1\lib\netstandard2.0\CSharpMath.Forms.dll
            C:\Users\vizid\.nuget\packages\csharpmath.skiasharp\0.5.1\lib\netstandard2.0\CSharpMath.SkiaSharp.dll   Test.Android            

原版本为CSharpMath 0.3.0,因存在已知问题需升级到0.5.1,但升级后出现上述冲突。

解决步骤

1. 添加程序集绑定重定向

在项目的App.config文件中添加以下配置,强制所有引用统一使用4.1.3.0版本的System.Numerics.Vectors:

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-4.1.3.0" newVersion="4.1.3.0" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>

如果是Android项目,需确保配置文件被正确包含到项目中,或直接编辑.csproj文件添加相关配置。

2. 手动安装指定版本的NuGet包

右键项目 → 选择「管理NuGet程序包」,搜索System.Numerics.Vectors,安装4.1.3.0版本,确保项目直接引用该版本,覆盖系统默认的2.0.5.0引用。

3. 调整项目文件中的引用优先级

编辑项目的.csproj文件,移除旧的系统引用条目,保留NuGet包的引用:

<!-- 保留这行NuGet引用 -->
<PackageReference Include="System.Numerics.Vectors" Version="4.1.3.0" />

<!-- 删除类似这样的系统引用 -->
<!-- <Reference Include="System.Numerics.Vectors, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
  <HintPath>C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\System.Numerics.Vectors.dll</HintPath>
</Reference> -->

4. 清理重建项目

  • 右键项目 → 选择「清理」
  • 删除项目目录下的bin和obj文件夹
  • 重新生成项目,确保所有引用重新加载

内容的提问来源于stack exchange,提问作者ViDanMaster

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 22:51:52