Understanding assembly redirections in app.config and web.config
Posted: (EET/GMT+2)
If you’ve ever opened a .NET app.config or web.config file and seen a long <assemblyBinding> section, you've encountered how .NET handles different versions of the same assembly.
When your application references version 1.0.0.0 of a library, but another dependency uses version 1.0.1.0, .NET can’t load both. The binding redirect tells it to load a single version for all references.
Here’s what it looks like:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json"
publicKeyToken="30ad4fe6b2a6aeed"
culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0"
newVersion="10.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
The above configuration means shortly put: if anything asks for "Newtonsoft.Json" versions up to 10.0.0.0, load 10.0.0.0 instead. The runtime applies this before the assembly is loaded, so everything stays compatible.
Visual Studio can generate these automatically when you build, but it's good to understand what they do, especially if you're debugging version mismatch errors like "Could not load file or assembly".