2

I build server applications using C#, .NETCore 2.0 on CentOS 7.6 using JetBrains Rider IDE (latest version). All my services are built as Docker images. I DONT use json.net in my OWN code (I use ServiceStack.Text) but many libraries use it and are causing a big mess with different versions! This problem exists mainly with .NETCore (usually less of a problem on Windows and 'full .NET frameworks'). Here is what I get as Warnings and errors: Version conflict:

/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]

When I start the service I get Could not load file or assembly:

2018-06-19 11:16:17.703 +02:00 [ERR] [OperationsManagerServer.AppHost] [ThreadId 1] Error registering BizBusRabbitManager(http://infraserver-tbws2:15672, admin, admin), Error: System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) File name: 'Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' at RabbitManagerLib.BizBusRabbitManager..ctor(String hostUrl, String username, String password) at OperationsManagerServer.AppHost.Configure(Container container) in /home/tbednarz/Projects/BizBusOpsManagerServer/OperationsManagerServer/AppHost.cs:line 276

This is caused by EasyNetQ library which uses Json.Net for serializing/de-serializing RabbitMQ messages.

If I look into the deps.json files in my bin/Debug.. folders I find lots of entries like

    "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"
},

But they all have the same version (10.0.2). So I have no idea where these problems are coming from and why it cannot load the dll.

I tried:

  1. dotnet nuget locals all --clear to get rid of old stuff which might be stored in the local nuget cache
  2. dotnet publish -c "Debug" which produces conflict warnings again

A sudo find / -name "Newtonsoft.Json.dll" on my CentOS box retuns many diffentet versions of Newtonsoft.Json on my disk:

/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

I did not install one of them directly but there is everything between 9.0.1 and 10.0.3 around but not the missing 11.0.0!

Does anybody have an idea, how I can get rid of this in .NETCore? Any hints would be greatly apreciated!

ThommyB
  • 1,456
  • 16
  • 34
  • are they build for the sae version (32bit or 64bit)? – Plexis Plexis Jun 19 '18 at 10:36
  • I have only 64 bit, but I don't know what the lib dependencies of all my dozens of libs are, I just install them using nuget from inside JetBrains Rider. – ThommyB Jun 19 '18 at 11:52
  • the located assembly's manifest definition does not match the assembly reference This is the specific error, are you sure there is no conflicts? can u update the libs? – Plexis Plexis Jun 19 '18 at 12:09
  • I have only two libs which are using Json.Net: [EasyNetQ](https://www.nuget.org/packages/EasyNetQ/) and [NJsonNet](https://www.nuget.org/packages/NJsonSchema/). I have removed both of them and added them back with latest versions, but no change in behaviour. NJsonNet is happy with Json.Net 9.0.1 or later. The conflict warnings start as soon as I add EasyNetQ. – ThommyB Jun 19 '18 at 12:30

1 Answers1

4

Workaround: Adding Json.Net 11.0.1 from Nuget to all projects that reported issues (even though I do NOT need it directly in my code), solved the problem. But for me this is just a work-around. It means that dependency management in .NET Core 2.0 is not working correctly under certain conditions!

Kirill Kobelev
  • 10,252
  • 6
  • 30
  • 51
ThommyB
  • 1,456
  • 16
  • 34
  • Fresh .NET Core 2.1.1 project with VS 15.8.1 and had to do the same thing. – TheEdge Aug 21 '18 at 11:35
  • Experiencing the same for .NET 5. I use `Newtonsoft.Json 13.0.1` in a couple of libraries. Another library wraps a third party one (`MassTransit.AmazonSQS 7.2.2`) which seems to be bringing `Newtonsoft.Json 11.0.2`. I have the problem ONLY when running the app within a docker container. If anyone knows WHY I'd forever grateful because this is a weird dependency hell. – diegosasw Oct 01 '21 at 15:42