frameworrk and GAC components



I need to present a list of assemblies as potential references, similar to
(but less sophisticated than) the Visual Studio project references dialog.

The reason for this is that my app supports scripting by dynamically
compiling VB.NET code (via CodeDom.Compiler), and I want to provide for the
selection of references required by the user's script project.

So I want the app to present a list of assemblies installed in the GAC,
including available framework system assemblies (e.g., System.Xml,
System.Data, System.Windows.Forms, etc.).

Is there a managed mechanism to enumerate GAC assemblies? In searching
about, I've found "DOC: Global Assembly Cache (GAC) APIs Are Not Documented
in the .NET Framework Software Development Kit (SDK) Documentation"
(;en-us;317540). But this
looks like C++, and I was hoping for a C# solution (I could even live
with/translate VB.NET).

Anyone have an idea of how to accomplish this?




Mattias Sjögren

Is there a managed mechanism to enumerate GAC assemblies?

Not in the framework, not. But you can call those COM APIs from C# if
you want.

But the GAC has nothing to do with compile time references. It's only
used when loading the assembly at runtime. The VS Add Reference
dialog, for example, does not list the contents of the GAC.



Thanks Mattias,

So what does the VS Add References dialog use? How can I get the list of
available references?

My dialog has a Browse button (for adding references not in the GAC), but if
you navigate to the GAC with the file open dialog, you get the same "funky"
view of the GAC that Windows Explorer shows (provided by SHFusion.dll), and
you can't actually select anything in the dialog.





Thank you Mattias,

FYI, I've poked around a bit more, and here's what I've found:

Gives the root folder of all installed framework versions; append the
version (e.g., "\v2.0.50727 ") to get the folder where a given framework's
dll files are installed

As the article notes:
HKLM\SOFTWARE\Microsoft\.NETFramework\AssemblyFolders (and HKCU)

But I also found:
This yields other VS components (like PIA's) and other public assemblies.

I have one more related question, which I'll post in a separate message - I
basically want to know if there is an easy/quick way to programmatically
identify a .NET assembly (EXE or DLL). One of the assembly folders you get
from the registry can have many files, but only 1 or 2 of which are .NET
assemblies. Is there a way to find them (other than trying to load each as
an assembly)?

Thanks so much for your help.


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