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.

When using .NET Standard facades on .NET Framework, automatic binding redirects should be enabled

See original GitHub issue

We now automatically inject facades into the .NET Framework compilation when consuming a library that targets .NET Standard.

We need to make sure that when these facades are injected, that we forcefully enable automatic generation of binding redirects. That’s necessary because we deploy files that might have higher versions then what the .NET Standard binary is referencing. These files aren’t necessarily part of the runtime unification table or are explicitly opted-out by a minor version bump.

In non-SDK-style projects, the property <AutoGenerateBindingRedirects> is defaulted to false and relies on project templates to be set. The latter is only the case when the project got created targeting .NET Framework 4.5.1 or later. When an existing project is upgraded to 4.5.1 or later, the property is still false. I suggest we set it to true when we detect .NET Standard facades are needed.

My understanding is that in SDK-style projects the <AutoGenerateBindingRedirects> is already true if the project is targeting .NET Framework and producing an application.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:20 (16 by maintainers)

github_iconTop GitHub Comments

5reactions
terrajobstcommented, Jul 24, 2017

I’d say this is a very severe bug we need to fix.

Scenario

  • The customer has an existing application targeting .NET Framework 4.5 or lower
  • The customer retargets the app to .NET Framework 4.6.1
  • The customer references a .NET Standard 1.6 class library (P2P or NuGet)
  • Customers runs the app

Expected Behavior

The app works.

Actual Behavior

The application crashes with FileNotFoundException:

Unhandled Exception: System.IO.FileLoadException:
Could not load file or assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
   at ConsoleApp3.Program.Main(String[] args)

Manually setting AutoGenerateBindingRedirect to True solves the problem, but there are no UI affordances for it and the error message isn’t actionable.

2reactions
terrajobstcommented, Jul 24, 2017

Weird, I thought I had verified that I get zero warnings. Turns out you’re correct, I get this:

image

In that case I think I’m OK with this being fixed in 2.1.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Enable or disable autogenerated binding redirects
You can enable automatic binding redirection for existing apps that target previous versions of .NET Framework (4.5 and earlier).
Read more >
Fakes Not Generated using .NET 4.7.1 after updating to ...
NET standard library forces the use of .NET standard system facade, it also means that a number of binding redirects are required. The...
Read more >
c# - How do I prevent .NET 4.7.1 libraries from copying the ...
NET Framework 4.7.2 you won't have any additional files copied to your bin folder and no binding redirects will be automatically generated.
Read more >
Binding Redirects
The fix if you're using .NET Framework · Enable <AutoGenerateBindingRedirects> (this doesn't work for web projects - it doesn't handle web.config ).
Read more >
Warning "Found conflicts between different versions of the ...
I updated our existing projects to 6.0, and now they show warnings "Found conflicts between different versions of the same dependent assembly.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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