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.

Binding redirects are not generated automatically even with AutoGenerateBindingRedirects

See original GitHub issue

There are two issues here:

  • First the <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> is not recognized. The warning message is wrong:
`<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net462</TargetFramework>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
    <PackageReference Include="WindowsAzure.Storage" Version="7.2.1" />
  </ItemGroup>
</Project>`
Produces a warning message saying: 

 `1>Consider app.config remapping of assembly "Newtonsoft.Json, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" from Version "6.0.0.0" [] to Version "9.0.0.0" [C:\Users\me\.nuget\packages\newtonsoft.json\9.0.1\lib\net45\Newtonsoft.Json.dll] to solve conflict and get rid of warning.

1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(1964,5): warning MSB3276: Found conflicts between different versions of the same dependent assembly. Please set the “AutoGenerateBindingRedirects” property to true in the project file. For more information, see http://go.microsoft.com/fwlink/?LinkId=294190.`

The information in the link says I should enable `AutoGenerateBindingRedirects`, but indeed `<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>`  is activated.
  • Second: No redirects are created. The assemblies try to access the same wrong version described in the error message.

It looks like the <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> is somehow overlooked.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:29
  • Comments:19 (7 by maintainers)

github_iconTop GitHub Comments

15reactions
JoseFMPcommented, Jun 20, 2017

@nguerrera Yes, after my last message I was trying new solutions and the one proposed in here worked for me. So, none of the other solutions had any effect. The only thing that created the redirects was adding the target:

<Target Name="ForceGenerationOfBindingRedirects"
          AfterTargets="ResolveAssemblyReferences"
          BeforeTargets="GenerateBindingRedirects"
          Condition="'$(AutoGenerateBindingRedirects)' == 'true'">
    <PropertyGroup>
      <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
    </PropertyGroup>
  </Target>

Without that the error will happen whenever I run the build in Windows. It happens both if the conflict is in a dependent dll or in the .exe (no difference at all).

11reactions
tomkludycommented, Mar 31, 2020

I had this problem and will add my own experience. First off, I ended up turning on <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType for all projects, both libraries and executables. I don’t know why this is not the default as this fixed dozens of projects by itself!

I still had a project that generated this mysterious error, even though it was definitely generating the *.dll.config file with all of the correct bindingRedirects. In my case, the problem was caused by a PackageReference that transitively pulls in Microsoft.Bcl.Build. This invisibly changed properties and added targets to the build. Once I turned up the build log verbosity to “Detailed” I found this:

1>Property reassignment: $(AutoUnifyAssemblyReferences)="false" (previous value: "true") at C:\Users\tomk\.nuget\packages\microsoft.bcl.build\1.0.21\build\Microsoft.Bcl.Build.targets (22,5)

Then later, while building target ResolveAssemblyReferences I confirmed:

1>    AutoUnify:
1>        False

… right before the string of errors.

I have no idea what this property is for, because the bindingRedirects were still created, so whether it liked it or not, the assembly references were unified anyway. I was able to fix the error by adding to my project file:

  <Target Name="ForceAutoUnify"
          BeforeTargets="ResolveAssemblyReferences"
          Condition="'$(AutoGenerateBindingRedirects)' == 'true'">
    <PropertyGroup>
      <AutoUnifyAssemblyReferences>true</AutoUnifyAssemblyReferences>
    </PropertyGroup>
  </Target>

Hopefully this will save time for others, as I was struggling with this for quite a while.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Enable or disable autogenerated binding redirects
Right-click the project in Solution Explorer and select Properties. · On the Application page, uncheck the Auto-generate binding redirects option ...
Read more >
Why doesn't AutogenerateBindingRedirects work for a Web ...
Inspecting the output from the build shows that binding redirects are generated just not in the Web.config. Instead, they are in ...
Read more >
Automatically generating assembly binding redirects
Automatically generating assembly binding redirects .NET has a weird way of referencing dependencies. When one "assembly" (EXE or DLL) ...
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 >
Auto-Generate Binding Redirects is not available - YouTrack
I have standard Web Forms Web application and feature is not available. Why? It should be available for all full .Net framework apps,...
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