tags:

views:

288

answers:

4

I'm trying to use Assembly.Load() to load an assembly that is in the GAC. For example, say I want to list out all of the types that exist in PresentationCore.dll, how would I go about loading PresentationCore.dll?

When I try this:

Assembly a = Assembly.Load("PresentationCore.dll");

I get a FileNotFoundException. Another answer on SO suggested I used Assembly.LoadFrom() to accomplish this - I'm hesitant to do that because Assembly.LoadFrom() is deprecated, according to Visual Studio 2008 - plus, it doesn't seem to actually work.

Any ideas?

+8  A: 
Andrew Hare
Perfect, thanks!
unforgiven3
+4  A: 

You need to pass the name of the assembly to Assembly.Load(), not the name of the DLL. If you open the DLL in Reflector, the name should be at the bottom of the window. In the case of PresentationCore.dll, the name should be something like PresentationCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.

Andy
+1 good point - it's the logical name of the assembly - not the physical file name - that's needed
marc_s
+1  A: 

I recommend you take a look at How the Runtime Locates Assemblies in the MSDN library to get an idea of what happens when the CLR attempts to load an assembly.

For diagnosing specific issues, the Fusion Log Viewer tool is fantastic. Suzanne Cook, one of the Fusion developers has a guide on her blog which has helped me out in the past.

Antony Perkov
A: 

Use GetAssemblyName (http://msdn.microsoft.com/en-us/library/system.reflection.assemblyname.getassemblyname.aspx) to get the fully qualified assembly name of the dll, and pass this to Assembly.Load().