Solved

assembly.load()

Posted on 2004-09-29
8
209 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Aspnet xml 2 36
C# System Cannot Find File Specified Error 4 55
asp.net mvc5 3 35
c# if statement weird reaction 3 29
Article by: Ivo
Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

707 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now