Is it possible to implement a COM interface with the generics.NET class?

I have the following interface that I am trying to make COM visible. When I try to create a type library, I don’t like the fact that my implementation class comes from a generic class.

Is it possible to use a common class as a COM implementation class? (I know that I could write a universal wrapper and export it to COM, but this adds another layer, which I would prefer without it.)

[ComVisible(true)] public interface IMyClass { ... } [ComVisible(true), ComDefaultInterface(typeof(IMyClass))] [ClassInterface(ClassInterfaceType.None)] public class MyClass : BaseClass<IMyClass>, IMyClass { ... } 

Error message:

  Warning: Type library exporter encountered a type that derives 
 from a generic class and is not marked as 
 [ClassInterface (ClassInterfaceType.None)].  Class interfaces cannot
 be exposed for such types.  Consider marking the type with 
 [ClassInterface (ClassInterfaceType.None)] 
 and exposing an explicit interface as the default interface to 
 COM using the ComDefaultInterface attribute. 
+7
generics com
source share
1 answer

Generic types and types that are derived from a generic type cannot be exported. Set ComVisible(false) to your MyClass type. You need to either create an implementation of a non-general class, or use only the interface.

+5
source share

All Articles