question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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 reports/.NET/NetStandard Win32Exception causes file not found.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.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:6
  • Comments:48 (16 by maintainers)

github_iconTop GitHub Comments

19reactions
weshaggardcommented, Jul 18, 2017

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:

<RestoreProjectStyle>PackageReference</RestoreProjectStyle>

There is also a good change you will need auto-bindingredirects as well so make sure that is set in your project:

<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
10reactions
babelshiftcommented, Aug 26, 2017

@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:

  • Console App.exe
  • Class Library1.dll

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set dependencies when I use .NET Standard 2.0 ...
dependencies don't flow from new NET Standard project to old desktop projects through project references link. A possible solution is to add ...
Read more >
PackageReference in project files - NuGet
In this article ... Package references, using <PackageReference> MSBuild items, specify NuGet package dependencies directly within project files, ...
Read more >
How to set dependencies when I use .NET Standard 2.0 DLL ...
dependencies don't flow from new NET Standard project to old desktop projects through project references link. A possible solution is to add the...
Read more >
Dependencies of project reference not copied to output ...
NET Standard library to solution and add that library as project ... it not to copy the right transitive dependencies into the bin...
Read more >
R.I.P project.json - Out with the new, in with the old
In order to support development of ASP.NET projects, the team decided to take the opportunity to develop a brand new project file format....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found