BendEg
BendEg

Reputation: 21138

Assembly binding added in compiled output (app.config)

If I compile my application, an assembly binding is added automatically in the output. The specific assembly binding is not in the app.config in Visual Studio but in the created application config.

Is there any way, to check why the assembly binding is added automatically? The option AutoGenerateBindingRedirects is not enabled.

I don't want to have the following assembly binding

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="System.IO.Pipelines" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.0.2.2" newVersion="4.0.2.2" />
  </dependentAssembly>
</assemblyBinding>

Furthermore, a completly differnt assembly version is installed.

EDIT

When looking into the compiler binlog result (compiled with msbuild /bl) this occurs:

enter image description here

This is pretty strange, because we've got the version 4.0.2.2 in the directory of 4.7.3

Thanks you very much!

Upvotes: 3

Views: 2812

Answers (1)

Mr Qian
Mr Qian

Reputation: 23858

Actually, BindingRedirect is the feature of the packages.config nuget management format and it still have a bit drawbacks.

Is there any way, to check why the assembly binding is added automatically? The option AutoGenerateBindingRedirects is not enabled.

This behavior is controlled by the nuget package itself and the packages.config nuget management format. Since your code uses the part from different versions of the assembly and packages.config management format does not have the ability to switch them automatically.

So BindingRedirect comes up. And so far, some nuget packages have added this feature with packages.config and when you install this nuget package by packages.config, it will automatically add the BindingRedirect and it is not controlled by us.

In order to abandon the BindingRedirect and all these complex issues, I suggest you could use the new PackageReference nuget management format. And it is a better one which has solved the BindingRedirect issue and optimized package management. And in this one, you do have to use BindingRedirect.

Suggestion

1) Right-click on the packages.config file--> click Migrate packages.config to PackageReference.

2) then delete any bindredirect on the app.config file.

3) delete any AutoGenerateBindingRedirects in your xxx.csproj file if you have.

4) close VS, delete .vs hidden folder under the solution folder, any bin and obj output folders.

enter image description here

5) restart your project and then build again to test it.

Upvotes: 2

Related Questions