Sam Gentile's Radio Weblog : Partying with .NET

 

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.

 
 

Programatically Determining if a PIA is in the GAC.

One of today's many tasks was trying to determine if a Primary Interop Assembly (PIA) is already in the GAC.

I have an installer program that needs to know whether PIAs are already installed in the GAC so that I won't install them twice. So the question is how can we programmatically tell whether the GAC contains a particular assembly?

References:

I found these articles:

Assembly.Load Method (AssemblyName)

ms-help://MS.VSCC/MS.MSDNVS/cpref/html

/frlrfsystemreflectionassemblyclassloadtopic1.htm

Assembly.LoadWithPartialName

ms-help://MS.VSCC/MS.MSDNVS/cpref/html/

frlrfSystemReflectionAssemblyClassLoadWithPartialNameTopic.htm

How the Runtime Locates Assemblies ms-help://MS.VSCC/MS.MSDNVS/cpguide/html/

cpconhowruntimelocatesassemblies.htm

The third article says that if you want to load an assembly from the GAC as opposed to just from the app directory, you need to call Assembly.LoadWithPartialName rather than Assembly.Load.

This is the best answer I've found so far: try to load the assembly then if that fails, then the assembly isn't there. This is lame, however. We don't want to load the assembly, we just want to know whether it exists or not.

One answer is that because it is PIA, installing it to the GAC with the same name will simply over-write it.

Jason Bock crufted up some code for me that reads the assemblies in the GAC and does comparison.

But then I find this and it turns out Mattias has figured out how to use the undocumented Fusion APIs!!! He has a sample here.



© Copyright 2002 Sam Gentile.
Last update: 6/26/2002; 8:56:24 AM.

Click here to visit the Radio UserLand website.