JamesNK / Newtonsoft.Json

Json.NET is a popular high-performance JSON framework for .NET
https://www.newtonsoft.com/json
MIT License
10.81k stars 3.26k forks source link

System.ComponentModel.TypeConverter 4.0.1 was not found - Causes failures in .Net Core and .Net Standard projects #1425

Closed GordonRudman closed 7 years ago

GordonRudman commented 7 years ago

NSubstitute had the same issue, so I'm basically going to copy bits and pieces of StefanKert bug report here:

Currently if Newtonsoft.Json is used with .NetCore or .Net Standard projects the following warning is generated when calling dotnet restore: warning NU1603: Castle.Core 4.0.0 depends on System.ComponentModel.TypeConverter (>= 4.0.1) but System.ComponentModel.TypeConverter 4.0.1 was not found. An approximate best match of System.ComponentModel.TypeConverter 4.1.0 was resolved.

This results in a warning for each referenced package that uses these assemblies (basically almost all my projects): image

This error is already fixed in castleproject/Core#239 so upgrading the version will probably fix this issue. Current version of System.ComponentModel.TypeConverter is 4.3.0

The dependency on the non-existent 4.0.1 package causes NuGet restore to float upwards. Each restore will try again to check if 4.0.1 exists on a source since it is the best match. Restore caches the list of versions from http feeds for 30 minutes, but after that it will again make http requests to each feed looking for the package again.

I'm currently hitting this due to Newtonsoft.Json (10.0.3) dependency on Castle.Core, and it is currently blocking progress on my project.

In .Net Core 2.0 / .Net 4.7 this actually causes dotnet restore to fail on the command line (but strangely not in VS2017) and blocks EF migrations from being generated. In VS2017 I end up with all sorts of other referencing issues instead, and this seems to break ReSharper too. This is the build failure I get via the CLI (but not VS) as soon as I reference a project that references Newtonsoft.Json:

C:\Program Files\dotnet\sdk\2.0.0\NuGet.targets(102,5): error : Unable to load the service index for source https://projectname.pkgs.visualstudio.com/_packaging/Store/nuget/v3/index.json.\r 
[C:\Code\Project\Project.Persistence.csproj]
C:\Program Files\dotnet\sdk\2.0.0\NuGet.targets(102,5): error :   Response status code does not indicate success: 404 (Not Found). [C:\Code\Project\Project.Persistence.csproj]
Build failed.
JamesNK commented 7 years ago

What? Newtonsoft.Json already uses System.ComponentModel.TypeConverter 4.3.0

https://www.nuget.org/packages/Newtonsoft.Json/10.0.3

JamesNK commented 7 years ago

Newtonsoft.Json (10.0.3) dependency on Castle.Core

This is also not true.

GordonRudman commented 7 years ago

My apologies - this was a bit of a Red Herring.

The warning message I was getting in Visual Studio was a bit misleading, but was all I really had to work from. To me, the warning message seemed to indicate that Castle.Core 4.0.0 depends on an older version of System.ComponentModel.TypeConverter, which it does, and which it couldn’t find anymore (perhaps MS deleted it or something). After searching the web, I found that NSubstitute basically had the same issue/warning message, because they were referencing an older version of Castle.Core. So, I jumped to the conclusion that Newtonsoft.Json was probably doing the same thing (referencing Castle.Core), and just hadn’t been updated yet.

What I probably should have done first, was to download all the source code and check for myself.
However, I assumed that it was a rather simple fix [just update to the newest package] that I didn’t spend the time to dig much further.

It turns out that this was more of a NuGet/VS issue than anything else, with the warning message showing up on the ‘wrong’ package.

Sorry for any inconvenience caused.

PS: Thanks for contributing such a useful library to the community.

JamesNK commented 7 years ago

No problemo, I've done the same thing once or twice myself :)