Solved

assembly.load()

Posted on 2004-09-29
8
215 Views
Last Modified: 2008-03-17
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
0
Comment
Question by:andyuk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 10

Expert Comment

by:123654789987
ID: 12178245
If u don't want to add a reference to the calling assembly, place the calling assembly in Global Assembly Cache
0
 

Author Comment

by:andyuk
ID: 12178282
thanks for getting back to me, how do i do that?
0
 
LVL 10

Accepted Solution

by:
123654789987 earned 250 total points
ID: 12178540
U have to first strong name the assembly using

sn -k keyPair.snk


Then u can install the assembly in GAC

To install a strong-named assembly into the global assembly cache
At the command prompt, type the following command:

gacutil –I <assembly name>

In this command, assembly name is the name of the assembly to install in the global assembly cache.
The following example installs an assembly with the file name hello.dll into the global assembly cache.
gacutil -i hello.dll
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 5

Expert Comment

by:tomasX2
ID: 12179053
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 );
0
 
LVL 3

Expert Comment

by:chintan_vaishya
ID: 12307554
0
 
LVL 3

Expert Comment

by:chintan_vaishya
ID: 12307565
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.
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question