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

Using Win32Exception with out of box netstandard1.3 project causes FileNotFoundException #19706

Closed
jnm2 opened this issue Dec 16, 2016 · 9 comments

Comments

@jnm2
Copy link
Contributor

jnm2 commented Dec 16, 2016

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.

Sample solution.

@karelz
Copy link
Member

karelz commented Dec 16, 2016

@weshaggard @ericstj any idea what's going on here?
System.ComponentModel.Win32Exception is part of netstandard1.3.

@tarekgh
Copy link
Member

tarekgh commented Dec 19, 2016

@ericstj could this be the same binding issue?

@clairernovotny
Copy link
Member

clairernovotny commented Feb 18, 2017

Ping? This is not good...

The Out-of-box version is 4.0.1 that gets copied to the output directory is but in-box components are looking for 4.0.0.0. Even with AutoGenerateBindingRedirects enabled, a binding redirect isn't being generated for this.

I just hit it with a net46 app that has a ref to netstandard 1.3 libs. Even with AutoGenerateBindingRedirects, a binding redirect was not created.

I had to manually add one.

To repro clone and check out the following commit:
https://github.com/onovotny/microsoft-authentication-library-for-dotnet
commit b437210265d4c5fa33729c0580b5ce1c2c4c54e6

Try to build
Remove the binding redirects from the app.config
https://github.com/onovotny/microsoft-authentication-library-for-dotnet/blob/b437210265d4c5fa33729c0580b5ce1c2c4c54e6/samples/DesktopTestApp/App.config

Build

https://github.com/onovotny/microsoft-authentication-library-for-dotnet/blob/b437210265d4c5fa33729c0580b5ce1c2c4c54e6/samples/DesktopTestApp/DesktopTestApp.csproj

Run the app. It fails with a FileNotFoundException due to it trying to load Microsoft.Win32.Primitives 1.0.0.0 but the output directory has 1.0.1.0 in it.

Add the binding redirect manually and it works.

@tarekgh
Copy link
Member

tarekgh commented Feb 19, 2017

I think we need to generate the binding redirect automatically and create a config file for the app. we have done such work for our internal netfx tests in our corefx repo.

@weshaggard is this something tracked to be done before shipping?

@ericstj do you have more info about the plan here?

@weshaggard
Copy link
Member

The Out-of-box version is 4.0.1 that gets copied to the output directory is but in-box components are looking for 4.0.0.0. Even with AutoGenerateBindingRedirects enabled, a binding redirect isn't being generated for this.

@onovotny which inbox components reference this? There should not be any inbox libraries that reference Microsoft.Win32.Primitives. There could be other OOB libraries that reference 4.0.0.0 and 4.0.1.0 versions of this library. However I would expect the auto-binding redirects feature to detect that case as well.

@clairernovotny
Copy link
Member

I guess I can't say for sure that it's OOB/in-box, just that it's easy to repro with my example above. Something in the dependency set was looking for 4.0.0.0 while 4.0.1.0 was in the output directory and no binding redirect was generated for it.

@weshaggard
Copy link
Member

@onovotny I wasn't able to get your solution to build and test. I was however with a couple of tweaks able to build and repo @jnm2's sample solution.

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.

@srivatsn is this a known issue in the current tooling or should we move this to the SDK repo?

@srivatsn
Copy link

Yes please move to SDK.

@weshaggard
Copy link
Member

Moved to dotnet/sdk#901.

@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 2.0.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants