Solved

assembly.load()

Posted on 2004-09-29
8
213 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
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 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