Solved

assembly.load()

Posted on 2004-09-29
8
210 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Office.Interop.Word Document - Detect Macros not working 16 37
Runtime Error 2 28
Remove greater than sign 3 46
Code works but it's slow 24 44
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

895 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

13 Experts available now in Live!

Get 1:1 Help Now