gpt4 book ai didi

c# - 编译时有多个版本的Newtonsoft.json

转载 作者:行者123 更新时间:2023-12-02 10:57:26 27 4
gpt4 key购买 nike

我使用Framework 4.6.1在.NET中处理混合ASP.NET类库项目。
编译prjoect时出现以下错误:

Error   CS0433  The type 'JObject' exists in both 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' and 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'    KBTryk3 D:\SourceCodes\Trykonline_3\Source\KBTryk3\Controllers\Api\CustomerController.cs

v6.0.0.0曾经存在于解决方案中,但我通过nuget软件包管理器更新为12.x.x.x,现在由于该错误而无法编译。
我已经搜索了整个解决方案,但找不到对旧的newtonsoft库的任何引用。

关于从哪里开始有什么建议吗?

最佳答案

我认为您可能有两个项目引用了不同版本的Newtonsoft。也有可能您正在使用一个需要特定版本的Newtonsoft的库,而不是您的项目引用的库。

检查解决方案中每个项目的引用,并确保(如果存在)Newtonsoft,则指向正确的版本(v12.0.0.0)。

如果那不能解决问题,则将程序集重定向添加到导致错误的项目的配置文件中:

<configuration> 
<!-- other sections in your file here -->
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed"/>
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

这将导致对旧版本的所有引用都路由到新版本。

关于c# - 编译时有多个版本的Newtonsoft.json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58524883/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com