我使用JetBrains Rider IDE(最新版本)在CentOS 7.6上使用C#,.NETCore 2.0构建服务器应用程序。我的所有服务都是作为Docker镜像构建的。我不在我的OWN代码中使用json.net(我使用ServiceStack.Text),但是许多库使用它并且导致不同版本的大混乱!这个问题主要存在于.NETCore中(通常不是Windows上的问题和完整的.NET框架')。 这是我得到的警告和错误: 版本冲突:
/usr/share/dotnet/sdk/2.1.103/Microsoft.Common.CurrentVersion.targets(2052,5): warning MSB3277: Found conflicts between different versions of "Newtonsoft.Json" that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed. [/home/tbednarz/Projects/BizBusOpsManagerServer/OperationsManagerServer.ServiceInterface/OperationsManagerServer.ServiceInterface.csproj]
OperationsManagerServer.ServiceInterface -> /home/tbednarz/Projects/BizBusOpsManagerServer/OperationsManagerServer.ServiceInterface/bin/Debug/netcoreapp2.0/OperationsManagerServer.ServiceInterface.dll
/usr/share/dotnet/sdk/2.1.103/Microsoft.Common.CurrentVersion.targets(2052,5): warning MSB3277: Found conflicts between different versions of "Newtonsoft.Json" that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed. [/home/tbednarz/Projects/BizBusOpsManagerServer/OperationsManagerServer/OperationsManagerServer.csproj]
当我开始服务时,我得到Could not load file or assembly
:
2018-06-19 11:16:17.703 +02:00 [ERR] [OperationsManagerServer.AppHost] [ThreadId 1]注册BizBusRabbitManager(http://infraserver-tbws2:15672,admin,admin)时出错,错误:System.IO。 FileLoadException:无法加载文件或程序集' Newtonsoft.Json,Version = 11.0.0.0,Culture = neutral,PublicKeyToken = 30ad4fe6b2a6aeed'。定位的程序集的清单定义与程序集引用不匹配。 (HRESULT异常:0x80131040) 文件名:' Newtonsoft.Json,Version = 11.0.0.0,Culture = neutral,PublicKeyToken = 30ad4fe6b2a6aeed' at RabbitManagerLib.BizBusRabbitManager..ctor(String hostUrl,String username,String password) 在/home/tbednarz/Projects/BizBusOpsManagerServer/OperationsManagerServer/AppHost.cs:line 276中的OperationsManagerServer.AppHost.Configure(容器容器)
这是由EasyNetQ库引起的,它使用Json.Net对RabbitMQ消息进行序列化/反序列化。
如果我查看deps.json
文件夹中的bin/Debug..
个文件,我会发现很多条目,例如
"Newtonsoft.Json/10.0.2": {
"type": "package",
"serviceable": true,
"sha512": "sha512-iwElSU2IXmwGvytJsezyDML2ZWDkG2JzTYzlU/BNlmzMdlmRvbnwITsGGY74gwVEpDli1UdOLkMT7/3jxWvXzA==",
"path": "newtonsoft.json/10.0.2",
"hashPath": "newtonsoft.json.10.0.2.nupkg.sha512"
},
但它们都有相同的版本(10.0.2)。所以我不知道这些问题来自何处以及为什么它无法加载dll。
我试过了:
dotnet nuget locals all --clear
摆脱可能存储在本地nuget缓存中的旧东西dotnet publish -c "Debug"
再次产生冲突警告我的CentOS盒子上的sudo find / -name "Newtonsoft.Json.dll"
在我的磁盘上重新调整了许多不同版本的Newtonsoft.Json:
/home/tbednarz/.local/share/JetBrains/Toolbox/apps/Rider/ch-0/181.4952.276/lib/ReSharperHost/Newtonsoft.Json.dll
/home/tbednarz/.local/share/JetBrains/Toolbox/apps/Rider/ch-0/181.4952.297/lib/ReSharperHost/Newtonsoft.Json.dll
/home/tbednarz/.nuget/packages/newtonsoft.json/10.0.2/lib/net20/Newtonsoft.Json.dll
/home/tbednarz/.nuget/packages/newtonsoft.json/10.0.2/lib/net35/Newtonsoft.Json.dll
/home/tbednarz/.nuget/packages/newtonsoft.json/10.0.2/lib/net40/Newtonsoft.Json.dll
/home/tbednarz/.nuget/packages/newtonsoft.json/10.0.2/lib/net45/Newtonsoft.Json.dll
/home/tbednarz/.nuget/packages/newtonsoft.json/10.0.2/lib/netstandard1.0/Newtonsoft.Json.dll
/home/tbednarz/.nuget/packages/newtonsoft.json/10.0.2/lib/netstandard1.3/Newtonsoft.Json.dll
/home/tbednarz/.nuget/packages/newtonsoft.json/10.0.2/lib/portable-net40+sl5+win8+wpa81+wp8/Newtonsoft.Json.dll
/home/tbednarz/.nuget/packages/newtonsoft.json/10.0.2/lib/portable-net45+win8+wpa81+wp8/Newtonsoft.Json.dll
/home/tbednarz/Projects/BizBusDataExchangeServer/BizBusDataExchangeServer/publish/Newtonsoft.Json.dll
/home/tbednarz/Projects/BizBusInvoiceServer/BizBusInvoiceServer/publish/Newtonsoft.Json.dll
/home/tbednarz/Projects/BizBusOpsManagerServer/packages/Newtonsoft.Json.10.0.3/lib/net20/Newtonsoft.Json.dll
/home/tbednarz/Projects/BizBusOpsManagerServer/packages/Newtonsoft.Json.10.0.3/lib/net35/Newtonsoft.Json.dll
/home/tbednarz/Projects/BizBusOpsManagerServer/packages/Newtonsoft.Json.10.0.3/lib/net40/Newtonsoft.Json.dll
/home/tbednarz/Projects/BizBusOpsManagerServer/packages/Newtonsoft.Json.10.0.3/lib/net45/Newtonsoft.Json.dll
/home/tbednarz/Projects/BizBusOpsManagerServer/packages/Newtonsoft.Json.10.0.3/lib/netstandard1.0/Newtonsoft.Json.dll
/home/tbednarz/Projects/BizBusOpsManagerServer/packages/Newtonsoft.Json.10.0.3/lib/netstandard1.3/Newtonsoft.Json.dll
/home/tbednarz/Projects/BizBusOpsManagerServer/packages/Newtonsoft.Json.10.0.3/lib/portable-net40+sl5+win8+wp8+wpa81/Newtonsoft.Json.dll
/home/tbednarz/Projects/BizBusOpsManagerServer/packages/Newtonsoft.Json.10.0.3/lib/portable-net45+win8+wp8+wpa81/Newtonsoft.Json.dll
find: \u2018/run/user/1000/gvfs\u2019: Permission denied
find: \u2018/tmp/.mount_jetbraMv9agN\u2019: Permission denied
/usr/share/dotnet/store/x64/netcoreapp2.0/newtonsoft.json/10.0.1/lib/netstandard1.3/Newtonsoft.Json.dll
/usr/share/dotnet/sdk/2.1.103/TestHost/Newtonsoft.Json.dll
/usr/share/dotnet/sdk/2.1.103/Sdks/Microsoft.NET.Sdk/tools/net46/Newtonsoft.Json.dll
/usr/share/dotnet/sdk/2.1.103/Sdks/Microsoft.NET.Sdk/tools/netcoreapp1.0/Newtonsoft.Json.dll
/usr/share/dotnet/sdk/2.1.103/Sdks/Microsoft.NET.Sdk.Publish/tools/net46/Newtonsoft.Json.dll
/usr/share/dotnet/sdk/2.1.103/Sdks/Microsoft.NET.Sdk.Publish/tools/netcoreapp1.0/Newtonsoft.Json.dll
/usr/share/dotnet/sdk/2.1.103/Newtonsoft.Json.dll
/usr/share/dotnet/sdk/NuGetFallbackFolder/newtonsoft.json/10.0.1/lib/netstandard1.0/Newtonsoft.Json.dll
/usr/share/dotnet/sdk/NuGetFallbackFolder/newtonsoft.json/10.0.1/lib/netstandard1.3/Newtonsoft.Json.dll
/usr/share/dotnet/sdk/NuGetFallbackFolder/newtonsoft.json/10.0.1/lib/portable-net45+win8+wpa81+wp8/Newtonsoft.Json.dll
/usr/share/dotnet/sdk/NuGetFallbackFolder/newtonsoft.json/10.0.1/lib/net20/Newtonsoft.Json.dll
/usr/share/dotnet/sdk/NuGetFallbackFolder/newtonsoft.json/10.0.1/lib/net35/Newtonsoft.Json.dll
/usr/share/dotnet/sdk/NuGetFallbackFolder/newtonsoft.json/10.0.1/lib/net40/Newtonsoft.Json.dll
/usr/share/dotnet/sdk/NuGetFallbackFolder/newtonsoft.json/10.0.1/lib/net45/Newtonsoft.Json.dll
/usr/share/dotnet/sdk/NuGetFallbackFolder/newtonsoft.json/9.0.1/lib/net20/Newtonsoft.Json.dll
/usr/share/dotnet/sdk/NuGetFallbackFolder/newtonsoft.json/9.0.1/lib/net35/Newtonsoft.Json.dll
/usr/share/dotnet/sdk/NuGetFallbackFolder/newtonsoft.json/9.0.1/lib/net40/Newtonsoft.Json.dll
/usr/share/dotnet/sdk/NuGetFallbackFolder/newtonsoft.json/9.0.1/lib/net45/Newtonsoft.Json.dll
/usr/share/dotnet/sdk/NuGetFallbackFolder/newtonsoft.json/9.0.1/lib/netstandard1.0/Newtonsoft.Json.dll
/usr/share/dotnet/sdk/NuGetFallbackFolder/newtonsoft.json/9.0.1/lib/portable-net40+sl5+wp80+win8+wpa81/Newtonsoft.Json.dll
/usr/share/dotnet/sdk/NuGetFallbackFolder/newtonsoft.json/9.0.1/lib/portable-net45+wp80+win8+wpa81/Newtonsoft.Json.dll
我没有直接安装其中一个,但是在9.0.1和10.0.3之间有一切,但不是缺少的11.0.0!
有没有人有想法,我怎么能在.NETCore中摆脱这个?任何提示都会大大贬低!
答案 0 :(得分:2)
解决方法::从Nuget中向所有报告问题的项目添加Json.Net 11.0.1(即使我在我的代码中不需要直接使用它)也解决了该问题。但是对我来说,这只是一个解决方法。这意味着.NET Core 2.0中的依赖项管理在某些情况下无法正常工作!