TweeZz
TweeZz

Reputation: 4919

Load an assembly that's not in the GAC or bin directory of a web application by using assembly name, not the path

I have a dll which is in directory xyz. Is there a way to load that dll without actually specifying the path?
I know I could load it simply by specifying the path to the dll, but then I bumped into a pretty annoying issue that forces me to copy that dll to my applications bin directory and load it using its name.
I would prefer though to not have that dll in the bin directory. So is there a way to load an assembly using its name which is actually not located in the GAC or bin directory?
Is there something I can do to have my web application scan additional directories for an assembly?

Upvotes: 2

Views: 2125

Answers (4)

Matt
Matt

Reputation: 498

As an alternative approach to the config based answers, you can register for the AppDomain.AssemblyResolve event.

This gives you a chance to run some code when assembly resolution fails, so you can try to rectify the problem at runtime (for example you could run a recursive directory search for the dll if you're feeling saucy).

This could be more flexible than using configuration, at the expense of some extra complexity.

Upvotes: 1

IanT8
IanT8

Reputation: 2217

You might want to look into assembly probing

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

and also check here: How the runtime locates assemblies: http://msdn.microsoft.com/en-us/library/15hyw9x3(v=VS.100).aspx

Upvotes: 4

Daniel Hilgarth
Daniel Hilgarth

Reputation: 174457

You can use the probing element in your web.config.
I doubt however, that this resolves your problem in the other question.

Upvotes: 2

Jethro
Jethro

Reputation: 5916

You can specify in you app.config where to look for assemblies.

<configuration>
    <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         <probing privatePath="bin;bin2\subbin;bin3"/>
      </assemblyBinding>
   </runtime>
</configuration>
  • By using the Probing Element.

Upvotes: 2

Related Questions