Dependency hell and file not found exception with Newtonsoft.Json

1

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!

c#
json.net
.net-core
rider
easynetq
asked on Stack Overflow Jun 19, 2018 by ThommyB

1 Answer

2

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!

answered on Stack Overflow Jun 19, 2018 by ThommyB • edited Nov 8, 2018 by Kirill Kobelev

User contributions licensed under CC BY-SA 3.0