Rushui Guan Rushui Guan - 1 month ago 10
C# Question

How to prevent Entity Framework 6 from Creating bindingRedirect in the config file

When compiling a project that references Entity Framework 6, it will sneakily insert the following assemblyBinding in the output config file:

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>


Is there any way to disable this? Please note that the section is inserted into the post compiled output config file not the dev copy. As a result it will overwrite my intended assemblyBinding for entity framework.

I actually want to do this because the project has dependencies on both EF5 and EF6.

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="entityFramework" publicKeyToken="b77a5c561934e089" />
<codeBase version="5.0.0.0" href="Legacy\EntityFramework.dll" />
</dependentAssembly>
</assemblyBinding>


Thanks!

Answer

It turns out that this is not causes by EntityFramework but Visual Studio. When Visual Studio detects that multiple versions of the same assembly are referenced, it will automatically create Assembly Binding Redirections.

But it can be disabled but editing the AutoGenerateBindingRedirects tag of the project file.

How to: Enable and Disable Automatic Binding Redirection

Comments