views:

38

answers:

1

I have a strongly-named assembly, installed to a specific folder (and not the GAC).

The name as shown in Reflector is:

"Foo.Bar.TreeFrog, Version=1.2.1.0, Culture=neutral, PublicKeyToken=ac88c4a8b22089b4"

and the path where it's installed is

"c:\\QueueBall"

Can I use Assembly.Load or Assembly.LoadFrom to load it, and if so how?

Can I ensure that the strong naming is honored, i.e. that the DLL I'm loading really is the one I'm expecting and not an imposter with the same name?

+2  A: 

You could use LoadFrom:

var assembly = Assembly.LoadFrom(@"c:\QueueBall\Foo.Bar.TreeFrog.dll");

Note that this will also load referenced assemblies into the application domain running this code. If you don't want this behavior you could use the LoadFile method.


UPDATE:

You can check the assembly identity before loading it to make sure that it has not been tampered with:

AssemblyName an = AssemblyName.GetAssemblyName(@"c:\QueueBall\Foo.Bar.TreeFrog.dll");
byte[] key = an.GetPublicKey();
Version version = an.Version;
Darin Dimitrov
Thanks. Is there any way to also check that the strong name is correct -- i.e. that somebody has not swapped in their own DLL with the same file name but the wrong signature?
Eric
@Eric, see my update.
Darin Dimitrov