Detect if My Own Assembly is installed... RRS feed

  • Question

  • I have an assembly that is to be installed in the GAC.  even though the phsyical location of the GAC is a folder, it isn't treated as such by windows.  So I can't simply do a:

    dir/s C:\Windows\assembly\GAC\*.*

    So how the ... ahem, how can i programmitically detect for the presence of a specific Assembly in the GAC?

    Jaeden "Sifo Dyas" al'Raec Ruiner

    (this is for a Prerequisite test application for an Installer)

    "Never Trust a computer. Your brain is smarter than any micro-chip."
    Tuesday, June 23, 2009 8:22 PM


All replies

  • try this:

    Basically, here's how the code can easily be added to your application:

    Assembly assm = null;
    if (((assm = Assembly.LoadWithPartialName("System")) != null) && assm.GlobalAssemblyCache)
        // exists in GAC.

    Where "System" is replaced by the name of your assembly.

    David Morton - - @davidmmorton - ForumsBrowser, a WPF MSDN Forums Client
    Tuesday, June 23, 2009 8:29 PM
  • Hey guys,

    Could be an easier way (although it was David's code that lead me to this) ... you should be able to do this from within the assembly thats running. The only thing with David's code is it needs to load the assembly (and it might put it to a different context) and perhaps the situation calls for that this code won't load the assembly. |
    Tuesday, June 23, 2009 9:14 PM
  • lost the formatting

    Assembly.GetExecutingAssembly().GlobalAssemblyCache |
    Tuesday, June 23, 2009 9:15 PM
  • lost the formatting

    Assembly.GetExecutingAssembly().GlobalAssemblyCache |

    That works great if the assembly you're trying to determine is the currently running assembly, but the OP stated that this is a prerequisite test for an installer, so I'm assuming two things:

    1) The installer will quit executing when finished, so loading the assembly into the AppDomain should cause minimal damage. 
    2) The Assembly he's trying to test is separate from the one testing it's existence.

    Derek, one more thing... check your post. Seems you may have malformed HTML in your first post. Everything's coming up blue.
    David Morton - - @davidmmorton - ForumsBrowser, a WPF MSDN Forums Client
    Tuesday, June 23, 2009 9:18 PM
  • Hey Dave,

    No worries mate, your right, my mistake. The formatting is completely messed up this post. |
    Tuesday, June 23, 2009 9:24 PM