Skip to content

Dependencies don't flow from new NETStandard project to old Desktop projects through ProjectReferences #901

@weshaggard

Description

@weshaggard

Copied 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.

https://github.com/jnm2/misc-codesamples/raw/master/Bug%20reports/.NET/NetStandard%20Win32Exception%20causes%20file%20not%20found.zip

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions