Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Unable to reference Newtonsoft.Json > 11.0.2 #2606
What You Are Seeing?
When referencing Newtonsoft.Json > 11.0.2, Cake fails when loading assembly. This is because Cake.Core (netstandard 2.0 only) and Cake.Nuget have a dependency on Newtonsoft.Json 11.0.2, which it loads during execution.
This is the same issue as captured under #2116, however the changes made to the resolver do not appear to work, as Cake is trying to load the assemblies based on absolute path.
I had previously submitted #2597 to pull in the latest version of Newtonsoft.Json at point of build, but this was rejected as it did not pin to a specific version (a point I concede).
I propose to update Cake.Core.csproj and Cake.Nuget.csproj to point directly to latest version of Newtonsoft.Json, which is, at the time of writing, 12.0.2.
What is Expected?
Assembly to be loaded without error
What version of Cake are you using?
Are you running on a 32 or 64 bit system?
What environment are you running on? Windows? Linux? Mac?
Windows & Linux, using dotnet core tool
Are you running on a CI Server? If so, which one?
N/A - issue occurs locally too.
How Did You Get This To Happen? (Steps to Reproduce)
Add the following to build.cake:
It took me a minute to grok what's going on here:
Updating to the latest version of Newtonsoft.Json will fix the issue short-term - until a newer version of Newtonsoft.Json comes out and someone tries to reference that as an addin. To fix this long-term, we'll need a similar code-based binding redirection like we did for the
My first instinct that we should replace this line with an
@mholo65 can you check my work and assumptions here?
I actually tried that in #2564 as I had problems loading
It's in Cake.Core, because the Microsoft.Extensions.DependencyModel 2.0.4 is referenced for netstandard, and this references Newtonsoft.Json >= 9.0.1
(and Cake.NuGet via NuGet.Packaging)
Hi all. Just wondering what your current thoughts are on this?
The Cake.Core dependency on Microsoft.Extensions.DependencyModel looks superfluous to me, given Cake uses Autofac. The version history suggests this was added when Cake was originally modified to support dotnet core, and I suspect it was a MS default addition. Rider/ReSharper suggests the reference is unused, and (with a very simple test case) Cake appears to still function under dotnet core without this reference.
Removing the Cake.Core dependency on Microsoft.Extensions.DependencyModel would allow the Cake.Core dependency on Newtonsoft.Json to also be removed, but the Cake.NuGet dependency on Newtonsoft.Json will need remain due to the dependency on NuGet.Packaging.
It sounds like you have some good ideas to improve assembly loading, but would it be worth breaking out that improvement into a separate issue? While work on that issue in progress, we could update the existing references to Newtonsoft.Json to latest (12.0.2), so anyone using cake on dotnet core can reference packages using Newtonsoft.Json > 11.0.2.