Search path for assemblies

  • Thread starter Thread starter Johannes Salmenhaara
  • Start date Start date
J

Johannes Salmenhaara

Hi,

Common framework looks for assemblies either from GAC or from the same
directory where the application is located. However some of my asseblies are
not in the application directory and they can not be added to GAC. Is there
any way the application can set the additional locations where to look for
assemblies?

Best regards,
Jaakko
 
Hi,

yes, you can add a probing element to your app.config file: -

<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="bin1;bin2\bin3;..\MyPrivatePath"/>
</assemblyBinding>
</runtime>
</configuration>

Here, it will search for the referenced assemblies in the path bin1,
bin2\bin3 relative to your assembly's path, and MyPrivatePath as root
relative to your assembly's path.

Let me know if you need anything else.

Thanks
Joyjit
 
Hi Joyjit,

Are you sure that ..\MyPrivatePath will work? At least I have not managed to
get anything but sub directories working. It seems that DLLs can only locate
on the root dir or on the sub directories but not on any other dir or drive.

Jaska
 
The probing element only works for sub directories. But you can use
<codeBase> to specify any path as long as your assemblies are strongly named.

HTH, Jakob.
 
You can only extend the probing path to subdirectories under the appbase, sibling directories will not be searched via probing.

The whole point of this is that without strong names there is no way for the runtime to guarantee that its picked up the correct assembly as it only performs file name matching. So you could accidently pick up an assembly that someone else wrote that just happened to have the same name as the one you intended. Thats why for non-strong named assemblies the assembly resolver works on the basis that the child assemblies are physically constrined within the Appbase and its subdirectories

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

Hi,

yes, you can add a probing element to your app.config file: -

<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="bin1;bin2\bin3;..\MyPrivatePath"/>
</assemblyBinding>
</runtime>
</configuration>

Here, it will search for the referenced assemblies in the path bin1,
bin2\bin3 relative to your assembly's path, and MyPrivatePath as root
relative to your assembly's path.

Let me know if you need anything else.

Thanks
Joyjit
 
Hi Jaska,

...\MyPrivatePath won't work. Your only chance to load assemblies
outside your executable's directory is Assembly.LoadFrom, but that
suffers from some limitations. You should find more than enough
information in Suzanne Cook's blog, which helped me a lot:

http://blogs.msdn.com/suzcook/

Christian
 
Back
Top