Side build problem

I have a simple application that loads two assemblies at runtime from 2 subfolders through this piece of code:

Assembly.Load("A, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"); Assembly.Load("B, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"); 

Directory structure:
enter image description here
Thus, the expected download is as follows:

 TheApp.exe -> A.dll -> C.dll (version 2.0.0.0) -> B.dll -> C.dll (version 1.0.0.0) 

Please note that C.dll signed, so both versions must be downloaded side by side.

To make the application load assemblies from the right places, I added the following to the application configuration file:

 <?xml version="1.0" encoding="utf-8" ?> <configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <probing privatePath="B;A" /> </assemblyBinding> </runtime> </configuration> 

The problem is the application crashes when a message appears every time it starts:

 === Pre-bind state information === LOG: User = ... LOG: DisplayName = C, Version=2.0.0.0, Culture=neutral, PublicKeyToken=93a02044a09d059a (Fully-specified) LOG: Appbase = file:///D:/Temp/TheApp/bin/Debug/Test/ LOG: Initial PrivatePath = NULL Calling assembly : A, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null. === LOG: This bind starts in default load context. LOG: Using application configuration file: D:\Temp\TheApp\bin\Debug\Test\TheApp.exe.Config LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v2.0.50727\config\machine.config. LOG: Post-policy reference: C, Version=2.0.0.0, Culture=neutral, PublicKeyToken=93a02044a09d059a LOG: Attempting download of new URL file:///D:/Temp/TheApp/bin/Debug/Test/C.DLL. LOG: Attempting download of new URL file:///D:/Temp/TheApp/bin/Debug/Test/C/C.DLL. LOG: Attempting download of new URL file:///D:/Temp/TheApp/bin/Debug/Test/B/C.DLL. WRN: Comparing the assembly name resulted in the mismatch: Major Version ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated. 

QUESTION : Why does the runtime look only at folder “B”? Why doesn't he continue to search for the correct version of the general assembly in folder A?

EDIT1 . I added the <codeBase> tag as follows, I know that there is the following in my configuration file:

 <?xml version="1.0" encoding="utf-8" ?> <configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <probing privatePath="B;A" /> </assemblyBinding> <dependentAssembly> <assemblyIdentity name="C" publicKeyToken="93a02044a09d059a" /> <codeBase version="1.0.0.0" href="B/C.dll"/> <codeBase version="2.0.0.0" href="A/C.dll"/> </dependentAssembly> </runtime> </configuration> 

Nevertheless, the problem remains!

+7
source share
1 answer

Check out the this note on the MSDN verification page that directly solves your problem:

If you have multiple versions of an assembly in a directory and want to reference a specific version of that assembly, you should use the <codeBase> element instead of the privatePath attribute of the <probing> element. If you use the <probing> element, the runtime stops checking the first time it detects an assembly that matches the name of a simple assembly, regardless of whether it matches the correct match or not. If this is correct, this assembly is used. If this is not a correct match, stops and linking of trial and error are not performed.

Runtime searches for version 2.0.0.0, but finds version 1.0.0.0 and stops searching.

The final solution changes the configuration file to the following:

 <?xml version="1.0" encoding="utf-8" ?> <configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <probing privatePath="B;A" /> <dependentAssembly> <assemblyIdentity name="C" publicKeyToken="93a02044a09d059a" /> <codeBase version="1.0.0.0" href="B/C.dll"/> <codeBase version="2.0.0.0" href="A/C.dll"/> </dependentAssembly> </assemblyBinding> </runtime> </configuration> 
+6
source

All Articles