Skip to content
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

ProjectLoadContext cannot be used to load project which references Newtonsoft.Json 8 #5756

Closed
natemcmaster opened this issue Apr 15, 2016 · 6 comments
Milestone

Comments

@natemcmaster
Copy link
Contributor

Steps to reproduce

Standalone repo: Archive.zip

What this repro does:

There are two independency projects, "Library" and "Loader".
"Loader" attempts to use Microsoft.DotNet.ProjectModel.ProjectLoadContext to load the "Library" assembly and instantiate Library.Banana via reflection.

Loader uses Newtonsoft.Json 7.0.0.
Library uses Newtonsoft.Json 8.0.0.

(For the purposes of the repro, I modified ProjectLoadContext to include a callback to log when assemblies are being loaded.)

Expected behavior

ProjectLoadContext.Load() should be called on to load "Newtonsoft.Json".

Evidence:

dotnet build Library\
dotnet run -p Loader\ Library\

Program output:

-------Start program----------
Loading assembly Library
Loading assembly Microsoft.Extensions.Primitives, Version=1.0.0.0
Loading assembly Newtonsoft.Json, Version=8.0.0.0
Done

Actual behavior

ProjectLoadContext.Load() is never called to load "Newtonsoft.Json"

dotnet build Library\
dotnet run -p Loader\ Library\

Program output:

-------Start program----------
Loading assembly Library, Culture=neutral, PublicKeyToken=null
Loading assembly Microsoft.Extensions.Primitives, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60

Exception has been thrown by the target of an invocation.
Could not load file or assembly 'Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Environment data

dotnet --info output:

.NET Command Line Tools (1.0.0-rc2-002374)

Product Information:
 Version:     1.0.0-rc2-002374
 Commit Sha:  f82da07fc4

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.10586
 OS Platform: Windows
 RID:         win10-x64
@natemcmaster
Copy link
Contributor Author

cc @anurse @davidfowl @NTaylorMullen here is a standalone for what we were discussing in person. May have something to do with TPA, but then again, "Microsoft.Extensions.Primitives" is in the TPA and it gets loaded just fine.

@analogrelay
Copy link
Contributor

but then again, "Microsoft.Extensions.Primitives" is in the TPA and it gets loaded just fine.

Does that version differ between the two projects? Because as long as they are the same, it would work fine. The problem is that Newtonsoft.Json is in the TPA list AND the versions differ.

@natemcmaster
Copy link
Contributor Author

Could be. Might explain why ProjectContextLoader.Load() gets called to load "Microsoft.Extensions.Primitives" but never gets called on to load Newtonsoft.Json.

@natemcmaster
Copy link
Contributor Author

Funny thing is if we reverse the version (e.g. "Loader" uses 8 and "Library" uses 7) the error goes away and user code loads and executes, but ProjectContextLoader.Load() still isn't called to load Newtonsoft.Json.

@analogrelay
Copy link
Contributor

Since this is targeted to Tooling RTM, I'm going to unassign myself so it can be re-triaged. I am going to be submitting a fix for #5602 shortly, but this one requires a bit of exploration still and I'm not sure I'll have the bandwidth as I transition back to ASP.NET stuff :). If it needs to come back to me, so be it, but I want to clarify the timeline and plan for this one since it is currently targeting Tooling RTM.

/cc @muratg @piotrpMSFT for re-examination. It might be good to sync up with @natemcmaster on what the status of this is post RC2/Preview1.

@analogrelay analogrelay removed their assignment Jun 1, 2016
@natemcmaster
Copy link
Contributor Author

I believe this has been fixed by changes in CoreCLR dotnet/coreclr#5144. I verified that TPA assemblies can be overriden by a load context now.

@msftgits msftgits transferred this issue from dotnet/cli Jan 31, 2020
@msftgits msftgits added this to the 1.0.0-rtm milestone Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants