Why is a "bindingRedirect" added to the app.config file after adding the Microsoft.Bcl.Async package?

C#.NetApp ConfigBase Class-Library

C# Problem Overview


I was wondering why nuget added the following code to my applications app.config file, after installing the Microsoft.Bcl.Async:

<runtime>
	<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
		<dependentAssembly>
			<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
			<bindingRedirect oldVersion="0.0.0.0-2.5.19.0" newVersion="2.5.19.0" />
		</dependentAssembly>
		<dependentAssembly>
			<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
			<bindingRedirect oldVersion="0.0.0.0-2.5.19.0" newVersion="2.5.19.0" />
		</dependentAssembly>
	</assemblyBinding>
</runtime>

If I remove this XML-element from the config, the app will not work properly.

As far as I understand it, we can use the bindingRedirect to make the app load a newer or older version of an assembly in case the version we were using when compiling the EXE is gone.
However I am using exactly the version 2.5.19.0, why would I need a redirect then?

the version of my dll

Why do I need this bindingRedirect?

C# Solutions


Solution 1 - C#

The assemblies Microsoft.Threading.Tasks and Microsoft.Threading.Tasks.Extensions are still referencing v1.5.11.0 of System.Runtime and System.Threading.Tasks.

Without the bindingRedirect, the Microsoft.* assemblies would try to load an old version of the System.* assemblies, which would fail.

Solution 2 - C#

You are simply saying whenever there is older version that is between 0.0.0.0 to 2.5.19.0, please replace that version with the new version that is 2.5.19.0

Let's say you don't have the older version available in your project and you are trying to access it, then you will end up with an error like "System.IO.FileLoadException: 'Could not load file or assembly"

So when your project is looking for an older version of that DLL it will simply replace that with new one which is available

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGameScriptingView Question on Stackoverflow
Solution 1 - C#Richard DeemingView Answer on Stackoverflow
Solution 2 - C#Bhargav KondaView Answer on Stackoverflow