Assembly Binding Redirection in .Net

May 02, 2013 by Anuraj

.Net .Net 4.0 ASP.Net Windows Forms

Today I come across an application crash due to version mismatch. The application executable was compiled using version 1.0.x.x, and we were using 6.2.x.x. Due to this version mismatch application was crashing.

Could not load file or assembly - error

Unfortunately we don’t have the source code of this application with us. Later I got one solution using bindingRedirect. This configuration element will help you to redirect referenced assemblies from one version to another using the app.config file.

<?xml version="1.0"?>
<configuration>
	<runtime>
		<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
			<dependentAssembly>
				<assemblyIdentity name="Microsoft.Ink" 
					publicKeyToken="31BF3856AD364E35" culture="neutral"/>
				<bindingRedirect oldVersion="0.0.0.0-6.1.0.0" 
					newVersion="6.1.0.0"/>
			</dependentAssembly>
		</assemblyBinding>
	</runtime>
</configuration>

We fixed the problem by creating an application.exe.config file with binding redirection inside it. By doing this you are instructing the application or DLL that during runtime, for a particular dependent assembly to use a particular version when an application and/or other assembly is looking for the older version.

You can find more details about binding redirection in MSDN.

Copyright © 2024 Anuraj. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Powered by Jekyll. Hosted with ❤ by GitHub