1

I'm checking the registry key HKEY_CLASSES_ROOT\CLSID\{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}\InprocServer32 to see if a managed .NET DLL is registered.

The Guid (x's) I'm getting from

    public static string AssemblyClassIDString(System.Reflection.Assembly assembly)
    {
        object[] objects = assembly.GetCustomAttributes(typeof(System.Runtime.InteropServices.GuidAttribute), false);
        if (objects.Length > 0)
        {
            return ((System.Runtime.InteropServices.GuidAttribute)objects[0]).Value;
        }
        else
        {
            return String.Empty;
        }
    }

The function returns a GUID but not the one matching the one inside the registry under CLSID. Does anyone know why this doesn't work?

Thanks

probably at the beach
  • 14,489
  • 16
  • 75
  • 116

2 Answers2

1

I always thought that the most reliable way to check if a COM DLL is registered or not is to try to create a type from the library.

Maybe you could follow this and instead of checking the registry, try to get a type reference with Type.GetTypeFromProgID for any known type from the library and then create an instance with Activator.CreateInstance.

It should not matter if your DLL is a regular COM or a .NET registered as COM.

Wiktor Zychla
  • 47,367
  • 6
  • 74
  • 106
1

The CLSID registry key is associated with types, not assemblies. Regasm.exe uses the Type.GUID property to determine what key to write. In other words, you'll have to iterate assembly.GetTypes(). First check for the [ComVisible] attribute, then check the guid. Beware that the registration can be customized with the [ComRegisterFunction] attribute so code like this is not a slamdunk.

The assembly's guid is in fact used, it generates the type library guid, the LIBID. Registering type libraries into HKCR\Typelib is pretty uncommon, it is only needed to make your component appear on COM import browsers or if you want to use the COM standard marshaller for cross apartment or process interop. Background info is available here.

Best way to ensure a COM server is registered is to just register it. Doing it more than once is not a problem.

bluish
  • 26,356
  • 27
  • 122
  • 180
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536