probing and bindingRedirect confusion
I am trying to understand both these subjects. I am reading Don Box and re-reading portions of Richter.
I created an exe CLRLoader with two class library projects Dll0, Dll1. Both of these build MyAssembly.dll. I created and added a strong name.
The main has this:
Assembly a = Assembly.Load(
"MyAssembly, Version=0.0.0.1, Culture=neutral, PublicKeyToken=a624f2519c903ae6");
a.CreateInstance(
"CodeAccessSecurity.CLRLoader.MyAssembly");
Of course this fails since the CLR doesn't know how to find MyAssembly. So I created an app.config as follows:
<?
xml version="1.0" encoding="utf-8" ?>
<
configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" >
<probing privatePath="Dll0;Dll1" />
</assemblyBinding>
</runtime>
</
configuration>
Now this works fine. It is interesting to use the Fusion Log viewer and delete the dlls and run the program. Deleting one cause the CLR to find the other, and vice versa. Works as advertised.
Now I want to play with bindingRedirect. I modified Dll1 to have a version of 1.0.0.1 instead of 0.0.0.1 and updated my app.config by adding
<dependentAssembly>
<assemblyIdentity
name="MyAssembly"
publicKeyToken="a624f2519c903ae6" culture="neutral" />
<bindingRedirect oldVersion="0-0.0.0.1" newVersion="1.0.0.1"/>
</dependentAssembly>
My 1.0.0.1 dll is not found given the privatePath I was using. Switching it to Dll1;Dll0. The correct dll is now found.
For the original case: Dll0;Dll1 - I am trying to understand why it failed. The fusion log finds the 1.0.0.1 dll in Dll0 first, loads it and quits with:
LOG: Attempting download of new URL file:///C:/tomr/projects/CodeAccessSecurity/CLRLoader1/Dll0/MyAssembly.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\tomr\projects\CodeAccessSecurity\CLRLoader1\Dll0\MyAssembly.DLL
LOG: Entering run-from-source setup phase.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: The assembly reference did not match the assembly definition found.
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
I guess I expected it to continue to Dll1 where it could find the correct dll. Oh well, a lot more to learn!