Search code examples
c#registrycom+

Avoid classes to be registered in a COM+ Serviced Component


I have a COM+ DLL that contains some classes that are primary and other auxiliary classes not used by the public methods. When registering the DLL using regsvcs command all the classes are added to registry and to TLB file.

There is any attribute or other solution to avoid adding the auxiliary classes to registry?

I have found ComVisibleAttribute attribute but it seems to be related only to inheritance.


Solution

  • ComVisibleAttribute is the correct attribute to use. In AssemblyInfo.cs you can use

    [assembly: ComVisible(false)]
    

    so that everything is not COM visible by default, and then for classes which you do want to be visible, precede them with

    [ComVisible(true)]
    public class MyClass
    

    Or flip it the other way round, if you want most types to be COM visible, and only a few to be invisible. I prefer everything invisible by default, as it gives me more control over exactly what is exposed to COM.