By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,202 Members | 1,467 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,202 IT Pros & Developers. It's quick & easy.

Interop issues

P: n/a
Hi,

I've written a C# dll and I'm trying to return a "List of structures" to my
C++ client application. I'm getting this warning while compiling my C# dll.

Warning 1 Type library exporter warning processing 'xyz'. Warning: Type
library exporter encountered a generic type instance in a signature. Generic
code may not be exported to COM.

Can someone guide me what needs to be done to resolve it?

Thanks,
Varun
May 21 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
COM does not support generic interfaces and therefore you can not directly
expose a generic type. In my opinion you normally shouldn't expose a generic
type directly anyway. I always create a class that derives from the generic
collection to isolate my clients. If you take this route then you can also
implement a custom COM-visible interface that exposes the collection to COM
without impacting the .NET clients. If you explicitly implement the
interface then the .NET clients won't even see the COM-visible interface.
Finally note that ICollection itself is COM-visible so COM clients can use
that as well.

[ClassInterface(ClassInterfaceType.None)]
[ComVisible(true)]
[Guid(...)]
public class MyComCollection : Collection<myobject>, IMyComCollection
{
int IMyComCollection.Count
{
get { return this.Count; }
}

void IMyComCollection.Add ( myobject obj )
{
this.Add(obj);
}
,,,
}

[ComVisible(true)]
[Guid(...)]
public interface IMyComCollection
{
int Count { get; }
void Add ( myobject obj );
...
}

Note that I highly recommend that all COM visible objects get an explicit
GUID otherwise every time you recompile a new GUID is generated resulting in
registry bloat and causing interop problems. I also recommend that you set
your assembly to not be COM visible by default and that you explicitly mark
each object as visible as needed to avoid unnecessarily publishing objects as
COM visible that you didn't mean to. Finally make sure that you use the
ClassInterfaceAttribute on your COM classes to prevent .NET from
auto-generating an interface for you.

COM interfaces do not support inheritance so avoid using inheritance in
interface definitions for COM. Also note that the first COM visible
interface on a class is considered its default interface and that the
ordering in the code does not necessarily indicate the visibility for this
purpose. .NET 2.0 added a new COM attribute to explicitly identify the
default COM interface for this reason so use it if possible.

"Varun Bansal" wrote:
Hi,

I've written a C# dll and I'm trying to return a "List of structures" to my
C++ client application. I'm getting this warning while compiling my C# dll.

Warning 1 Type library exporter warning processing 'xyz'. Warning: Type
library exporter encountered a generic type instance in a signature. Generic
code may not be exported to COM.

Can someone guide me what needs to be done to resolve it?

Thanks,
Varun

May 21 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.