HowTo: dynamically load assembly from GAC

  • Thread starter Thomas W. Brown
  • Start date
T

Thomas W. Brown

I need to dynamically addref a system assembly at runtime (for dynamically
generated code), but Assembly.Load is failing (I'm just specifying the
assembly name but no other components of the full name).

In particular,
Assembly.Load("System.Runtime.Remoting")

fails for me with an "Could not load file or assembly
'System.Runtime.Remoting' or one of its dependencies. The system cannot find
the file specified." error.

I suspect this is because, according to the Assembly.Load documentation,

"You can also make a dynamic reference to an assembly by providing the
calling method with only partial information about the assembly, such as
specifying only the assembly name. In this case, only the application
directory is searched for the assembly, and no other checking occurs. You
make a partial reference using any of the various methods for loading
assemblies such as System.Reflection.Assembly.Load or System.AppDomain.Load."

So, I need the long name of the assembly in order to load from the GAC.
Which brings me to the operative question...

What is the best (easiest) way to determine the proper long name for an
assembly in the GAC so that I can dynamically load said assembly?

Regards,
-- TB
 
P

Phil Wilson

Which one do you want? There could be (perhaps at least) two in the GAC. If
you know which one you want (such as 2.0) try specifying its assembly
version and perhaps string name too.
 
T

Thomas W. Brown

I pretty much want the latest one available. That is, I would like the
functionality of the deprecated Assembly.LoadWithPartialName() routine.

In any case, I have two workable solutions (three if you count bringing in
the COM based fusion library from the SDK); 1) just use the deprecated
routine, 2) walk the GAC file system myself and find the assembly location.

Regards,
-- TB
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top