April 05, 2006

Two common attribute mistakes while using the .NET interop

1. ClassInterface attributes

To expose .NET Assembly in COM create a public interface by using methods and properties that you want to expose in the TLB file, and then implement the interface in the class.

Make sure to have [ClassInterface(ClassInterfaceType.None)] before your class so that IntelliSense Features appears in COM.

public class MyTestClass : IMyInterface

2. ComVisible attribute

Setting ComVisible to false makes the types in this assembly not visible to COM components. If you need to access a type in this assembly from COM, set the ComVisible attribute to true on that type. By default it sets to false.

[assembly: ComVisible(true)]