Search code examples
.netvb6assembly-resolution

Configuring Custom Assembly resolution for assemblies dependent on a class library


OK, here is the setup:

  • A VB6 .exe that consumes some .Net classes.
  • The classes reside in 5 .dll's but are exposed through one COM visible wrapper .dll
  • Using an application manifest I can store the COM visible MyCOMVisibleWrapper.dll (and .tlb) wrapper in a subfolder named MyCOMVisibleWrapper.
  • I would like to store the dependent .Net .dlls in that folder too.
  • However the CLR looks for these .dll's in the folder where the VB6 executable resides, not in the folder where the wrapper .dll lives.

How can I add the MyCOMVisibleWrapper folder to the resolution path? I tried including a MyCOMVisibleWrapper.dll.config file with a <probing privatePath=MyComVisibleWrapper/> tag, but that doesn't work. I read about implementing the AssemblyResolve EventHandler but I am unsure about where to put that, as the .Net code has no main entry point.


Solution

  • You have to make a config file named MyVB6App.exe.config that has the following content:

        <configuration> 
         <runtime>
           <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
              <probing privatePath="MyCOMVisibleWrapper"/>
           </assemblyBinding>
         </runtime>
       </configuration>
    

    Now you can put the whole shebang, apart from the MyVB6App.exe.Manifest in the MyComVisibleWrapper folder.

    Look here for a more extensive discussion