Dependencies don't flow from new NETStandard project to old Desktop projects through ProjectReferences
See original GitHub issueCopied from https://github.com/dotnet/corefx/issues/14565.
From @jnm2
Am I doing something incorrect? I was not sure if this is the same problem as the other problems I’ve had with netstandard. Just by luck, every single one of my forays into netstandard have failed with this same type of issue. I have great confidence that it’s just me and these will all be fixed by VS2017’s RTM.
Create a new .NET Standard library targeting netstandard1.3. Create a static method Class1.DoWork() that throws new Win32Exception(). Add a .NET Framework console app targeting net462 In Program.cs, call Class1.DoWork() and add a reference to the library project. Run the console app and get:
System.IO.FileNotFoundException occurred
HResult=0x80070002
Message=Could not load file or assembly 'Microsoft.Win32.Primitives, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Source=NetstandardLibrary
StackTrace:
at NetstandardLibrary.Class1.Works() in C:\Users\Joseph\documents\visual studio 2017\Projects\NetstandardOnDesktop\NetstandardLibrary\Class1.cs:line 10
at DesktopConsoleApp.Program.Main(String[] args) in C:\Users\Joseph\documents\visual studio 2017\Projects\NetstandardOnDesktop\DesktopConsoleApp\Program.cs:line 9
Is this a binding redirect issue or something? I hope this isn’t the way things are intended to be? As long as this type of error exists, can you please maintain a netstandard troubleshooting document with step-by-step guidance for the workaround?
I would hope that scenarios like this would be covered by integration tests.
From @weshaggard
Looking at his solution the issue stems from the fact that the ProjectReference from the DesktopConsoleApp to the NETStandardLibrary project isn’t flowing the dependencies correctly so it isn’t seeing Microsoft.Win32.Primitives at all. It isn’t even an issue with binding redirects in this case it is just a missing dependency. To workaround it you can add a reference to the Microsoft.Win32.Primitives nuget package to the DesktopConsoleApp. However this sounds like a tooling issue where dependencies aren’t flowing.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:6
- Comments:48 (16 by maintainers)
Top GitHub Comments
For anyone that might still be hitting this you can workaround it by explicitly making the .NET Framework project a ProjectReference based project by setting the following property in the project:
There is also a good change you will need auto-bindingredirects as well so make sure that is set in your project:
@davidfowl So what’s the long term solution here? Using the
PackageReference
solution? Googling about this problem reveals a lot of confusion around this behavior, and the documentation could be more clear (unless I’m missing some important docs).Please help me understand a bit more.
Console App (.NET 4.6.1) -> Class Library 1 (.NET 4.6.1) -> Class Library 2 (.NET Standard 2.0) -> NuGet Package (Newtonsoft.Json)
After build, the Console App’s bin directory contains:
This will fail at runtime because Class Library 2.dll and Newtonsoft.Json.dll are non-existent.
The Visual Studio tooling seems to offer no assistance to remedy this unless I’m missing something.