List all DLL's implementing a specific interface from the GAC

后端 未结 5 1820
借酒劲吻你
借酒劲吻你 2021-01-21 09:49

Aloha

Given a plug-in architecture (C# / .NET 3.5) with the plug-ins stored in the GAC, how can I list/load all dll\'s that contain types that implement my specific inte

5条回答
  •  悲&欢浪女
    2021-01-21 10:23

    The Gac is really just a directory on your machine like any other. Here's the typical breakdown:

    c:\windows\assembly\GAC
    
                       \GAC_32
    
                       \GAC_MSIL
    

    And maybe some others..

    Within each of those folders, you'll find subfolders where the actual dll's are stored. You'll first need to write a recursive method to get you all the dll's found under \assembly\, (you can find these online easily if you're not comfortable doing it yourself). Once you have that list of dll's you can proceed to use Assembly.LoadFile to load up the assembly and check all the types to see if they implement a given interface.

    My only suggestion would be to load up these dll's in a seperate appdomain so that you're not allowing any potential harmful dll's to get loaded into your app.

    Some links:

    Searching Directories.

    Loading Assemblies and checking for a given interface.

    Creating new AppDomain.

提交回复
热议问题