Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Binding Redirection for Compilation

Tags:

c#

.net

I'm getting the following error when I try and compile a utility, which uses files that have been deployed to our client.

Assembly '*A* version 2.0.1.2' uses '*B* version 1.1.39.0' which has a higher version than referenced assembly '*B* version 1.1.32.0'.

Our client can use these DLLs no problem, because we have a binding redirection config file in place, which takes effect at run-time:

<dependentAssembly>
  <assemblyIdentity name="*B*" publicKeyToken="..." culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="1.1.32.0" />
</dependentAssembly>

To give a bit of background, the DLLs exist in separate solutions, and therefore some of the references are file references rather than project references, just something I have to live with!

Is there any equivalent binding redirection that applies at compile time?

I've tried compiling using debug DLLs (version 1.0.0.0), with source rolled back to the relevant version above, however I get the following error at run-time:

The located assembly's manifest definition does not match the assembly reference

Maybe the build server is configured differently to my machine, but anyway that didn't seem to work...

like image 988
Lee Avatar asked Feb 19 '14 16:02

Lee


People also ask

How do I set binding redirect?

Specify assembly binding in configuration files. You use the same XML format to specify binding redirects whether it's in the app configuration file, the machine configuration file, or the publisher policy file. To redirect one assembly version to another, use the <bindingRedirect> element.

What is automatic binding redirection?

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.

What is Assemblybinding?

<dependentAssembly> <assemblyIdentity name="FooBar" publicKeyToken="32ab4ba45e0a69a1" culture="en-us" /> <bindingRedirect oldVersion="7.0.0.0" newVersion="8.0.0.0" /> </dependentAssembly>


1 Answers

I doubt it's possible to "fix" it as you want to. If you read documentation for that compile error (https://msdn.microsoft.com/en-us/library/416tef0c.aspx), you will see that you can either update code to use the same version, or reference both versions during compilation (not an option in your case).

Imagine, that version 1.0.0.0 contains method MyMethod(), but version 1.0.0.1 contains MyMethod(string), and first version is used by assembly A, second version is used by assembly you are compiling. How do you want compiler to resolve this? In runtime, when you use binding redirection, only one version of assembly will be loaded still. Here, you do not own code for assembly A (which you are refering to, and which in turn references MyMethod), and reference to assembly 1.0.0.0 is embedded in A's manifest.

Long story short - I suppose only way to solve it for you is use assembly A which references the same version of B as you do.

like image 181
Evk Avatar answered Sep 20 '22 15:09

Evk