We're using Microsoft's Unity framework for dependency injection in some new class libraries. The main app is using some of the other enterprise libraries (Common and Logging) which are expecting Unity v2.0.414 but we implemented our libraries using Unity v2.1.515.
To get around the version differences I created an app.Config for the main app and placed an bindingRedirect entry into the config file and that has been working great. However we just learned that the app to this point has never used an app.config and mgmt prefers it this way.
So is it possible to programmatically implement an assembly redirect (i.e. in code)? Thanks!
To redirect one assembly version to another, use the <bindingRedirect> element. The oldVersion attribute can specify a single assembly version or a range of versions. The newVersion attribute should specify a single version. For example, <bindingRedirect oldVersion="1.1.
Binding redirects are added if your app or its components reference more than one version of the same assembly, even if you manually specify binding redirects in the configuration file for your app. The automatic binding redirection feature affects desktop apps that target . NET Framework 4.5. 1 or a later version.
Did you try with the AppDomain.AssemblyResolve event?
This post may help you as well How to use Assembly Binding Redirection to ignore revision and build numbers
public void Load(string assembly)
{
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(Method);
Assembly assembly = Assembly.LoadFrom(assemblyFile);
// ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With