all groups > dotnet interop > august 2005 >
You're in the

dotnet interop

group:

How to Hide Generics from Type Library Exporter


How to Hide Generics from Type Library Exporter Tom Z.
8/26/2005 6:26:02 PM
dotnet interop:
Hi All,

I'm trying to make an assembly in C# to use as a COM server. I'm building as
normal and ruinning regasm at the end. Everything is generally working,
except that I'm having a problem hiding some generic implementation base
classes from the type library exporter.

Here is a code sample:

-------------------------------------------------------

public interface IContainer
{
// imagine some stuff here
}

[ComVisibleAttribute(false)]
public class Container<T>
{
// imagine some stuff here
}

[ComDefaultInterfaceAttribute(typeof(IContainer))]
[ClassInterface(ClassInterfaceType.None)]
public class Test : Container<int>, IContainer
{
}

-----------------------------------------------------

This code compiles properly, but regasm gives this warning:

"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."

The class is skipped and not exported. What am I doing wrong here?
Re: How to Hide Generics from Type Library Exporter Pedro Ramilo
8/29/2005 12:00:00 AM
i wrote something similar in VB2005 Beta 2 and regasm simply seems to ignore
these properties and doesn't expose them, returning and error.
The resulting COM "interface" has only the COM supported features.
To work around these problems, I created a SUB that wraps up the creation
and manipulation of Generics.
COM does not seem to handle Generics but you can create Subs to which you
pass the arguments to get them to do the work with the Generics inside .Net.

I must say that although this seems Ok I couldn't get my assembly to be
consumed by VBA with an automation error. I don't think it's related to
Generics because TLB export terminates sucessfully (only a couple of
warnings due to the generics) and the error appears as soon as the class is
instanciated but anyway just to let you know if you run into the same
problem.....

Pedro


"Tom Z." <none> escreveu na mensagem
news:B05981C0-7A48-44EF-9D5F-64E8A045365F@microsoft.com...
[quoted text, click to view]

AddThis Social Bookmark Button