Link to home
Start Free TrialLog in
Avatar of andyuk
andyuk

asked on

assembly.load()

I am trying to load an assembly dynamically, the problem i have is the dll that we are trying to reference is in a different folder from the app calling it, when i try the assembly.load it cant find the assembly.  So when i add a reference to the calling solution it works.  is there away to get around this problem, i do not want the solution to know anything about the assembly we are trying to access.

Thanks in advance

Andrew
Avatar of 123654789987
123654789987

If u don't want to add a reference to the calling assembly, place the calling assembly in Global Assembly Cache
Avatar of andyuk

ASKER

thanks for getting back to me, how do i do that?
ASKER CERTIFIED SOLUTION
Avatar of 123654789987
123654789987

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you can also load the assembly without putting it into the gac if you have the fullPath to the assembly...
Assembly objAssembly = Assembly.LoadFrom( fullPath );
Also checkout this text,

Copy- pasting from somewhere,

I have several .NET assemblies (dll) I've developed which I use in my applications. Every time I create new site, IDE copies them to a bin directory (since I declare it as Copy Local). When I deploy the application on production server, I have to copy all dlls from the bin directory on my computer to the proper directory on server. How can I tell the .NET framework to load assemblies from another directory, say c:myCommons without using Assembly.Load? Can I do it just by playing with enviroment variables or the registry or maybe some properties of .NET framework?

You can specify an alternate directory source for assemblies outside of the application directory structure by specifying a <codebase> setting within a publisher policy file. This requires you to strongly name your assemblies and you must specify the specific assembly version that the codebase binding applies to. The following application configuration shows how to locate version 1.0.0.0 of the ServerLib assembly in the c:\SharedDependencies directory:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
   <runtime>
      <assemblyBinding
      xmlns="urn:schemas-microsoft-com:asm.v1">
         <dependentAssembly>
         <assemblyIdentity name="ServerLib"
                           publicKeyToken="ada0a9d1dd805043"
                           culture="neutral" />
         <codeBase version="1.0.0.0"
                   href="c:\SharedDependencies\ServerLib.dll"/>
       </dependentAssembly>
      </assemblyBinding>
   </runtime>
</configuration>

If you are trying to share assemblies between multiple applications, you should consider using the Global Assembly Cache (GAC), which removes the need for specifying a publisher policy to override how the runtime locates assemblies. The runtime always looks to the GAC first for an assembly. This also requires that assemblies are strongly named, but in general using strong names is recommended so that you can leverage version control and security features of the .NET runtime.

Hope this will be useful.
Good luck.
Chintan.