locked
ClassInterfaceType RRS feed

  • Question

  • User2036759390 posted

    Hi,

    I am including 

    [ClassInterface(ClassInterfaceType.AutoDual)] attritube to my .net class for calling the .net class in the COM environment. Now,the interoperability is fine and able to call the c# classes in to my COM.But, can we have any setting or property in c# which doesn't take [ClassInterface(ClassInterfaceType.AutoDual)] explicitly at the class level. Can we prevent this attritube [ClassInterface(ClassInterfaceType.AutoDual)] and have any setting to set this attribute in the c# without mentioning at the class level.

    -Shanenarrifield

    Tuesday, June 8, 2010 7:36 AM

All replies

  • User-1094143783 posted

    See this blog post for the expanation of the first problem. The point is that unless you specify ClassInterfaceType.None an extra interface is generated and this can cause problems with binary compatibility if you alter the order of methods, change their signatures or remove some of them. A much better alternative is to explicitly define an interface and inherit your class from it specifying ClassInterfaceType.None.

    ComVisible(true) is not a must for COM visibility. By default all public methods of public classes and all public classes are COM visible, all other entities are not COM visible. If you need to alter this you use ComVisible attribute, usually to decrease the amount of COM visible classes since for every COM visible class registry entries and type library entries are generated and this causes unnecessary registry pollution and inflates the type library. IMO it's a good idea to explicitly mark all public entities with ComVisible.

    Sunday, April 21, 2013 4:15 PM