-
-
Notifications
You must be signed in to change notification settings - Fork 724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Loading Newtonsoft.Json in Cake.CoreCLR throws during assembly loading #2116
Comments
When running with
(TPA = trusted platform assemblies) So it looks like the version of JSON.NET that ships with .NET Core SDK 2.1.103 is 9.0.1 (located at "C:\Program Files\dotnet\sdk\2.1.103\Newtonsoft.Json.dll"). A little further down I also see this:
And then finally this:
So the real question is: why does Cake have a problem loading a different version at runtime? Clearly other .NET Core apps can bind to a different version, otherwise there'd be a major outcry given how popular the library is. |
Starting to think that Newtonsoft.Json being in the TPA list is a red herring and doesn’t really have anything to do with this. Instead, my new theory is that this is a case of the Cake This is t a problem if an addin or tool uses a version of that assembly lower than the one Cake is binding to directly, but if the addin or tool needs a higher version it’s going to have a bad time. One possible solution could be to hook assembly resolution and return whatever assemblies were already loaded regardless of the version - basically doing binding redirects to the previously loaded version. That could work as long as the addin or tool doesn’t require functionality in the higher version. I’ll continue to look at this tomorrow, but wanted to get some thoughts down in case anyone had other ideas or feedback. |
@daveaglick yes it’s a transitive dependency. It’s at least loaded via Wonder if adding a binding redirect to app.config fixes this issue? E.g. For Newtonsoft.Json (support a large range of versions). Here’s the transitive dependency. https://www.nuget.org/packages/NuGet.Protocol/4.6.0 |
@mholo65 But Cake.CoreCLR is executed via I got curious about which assemblies are loaded into the script host context at runtime:
Here's the full list:
But no
Boom:
Which is the version that sits alongside I'm pretty sure this is what's going on:
This means that:
Not a great situation given how popular To try and figure out a way around it, I started playing with runtime binding redirection by hooking assembly resolution and adding this to my build script:
Which solves my own problem:
But still isn't ideal given that:
Not sure how to solve across the board... Maybe ship the latest and greatest version of |
PR incoming. I updated the version of
|
Looks like the only version of Newtonsoft.Json package available for scripts is 11.0.2 as of now. Is there a way to pick another version of this package as a build script addin? |
Using the * notation. This will bring in the latest stable version at compile time, and reference that. This is related to cake-build#2116, which is not resolved on dotnet core.
Using the * notation for version spec (latest stable version). This will bring in the latest stable version at compile time, and reference that. Related to cake-build#2116, which is not resolved on dotnet core, and causes exceptions when referencing Newtonsoft.Json.
What You Are Seeing?
Loading Newtonsoft.Json in Cake.CoreCLR throws during assembly loading.
What is Expected?
Rainbows and sunshine.
What version of Cake are you using?
Cake.CoreCLR 0.26.1
Are you running on a 32 or 64 bit system?
64
What environment are you running on? Windows? Linux? Mac?
Windows
How Did You Get This To Happen? (Steps to Reproduce)
Run the following
build.cake
:Raw assembly loading also fails:
Output Log
It's not totally clear why this is happening. Suspicion is that it has something to do with the .NET SDK already containing a custom build of Newtonsoft.Json and the assembly load conflicting with that.
The text was updated successfully, but these errors were encountered: