Delen via


Interoperating Using Generic Types

The COM model does not support the concept of generic types. Consequently, generic types cannot be used directly for COM interop.

Non-Supported Actions

The following actions are not supported and will fail with an E_NOINTERFACE error:

  • Accessing generic interfaces from COM.

  • Accessing class interfaces for nongeneric classes that derive from generic classes.

  • Generating class interfaces for generic classes. For example, the _MyGenericType interface cannot be generated for the MyGenericType<T> class.

Supported Actions

You can access a generic class indirectly using a nongeneric base interface. For example, consider the following type:

[C#]

class MyClass <T> : IMyClass, IEnumerable<int>
{
   …
}

COM clients can make calls to instances of this type using the IMyClass interface, but calls to either _MyClass, _MyClass <T> or IEnumerable<T> will fail.

See Also

Reference

Generics (C# Programming Guide)

Other Resources

Interoperating with Unmanaged Code

Generics (Visual C++)