Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to export generic types to COM? Type library exporteder encountered a generic type instance in a signature

Tags:

c#

.net

com

I have a method with a default parameter:

void Test(int? iRange = null);

When trying to expose my class to COM, I get a warning:

Type library exporter encountered an generic type instance in a signature. Generic code may not be exported to COM. Is it possible to some how expose this method?

Edit Sorry, i think this is to do with the nullable parameter (not the default parameter) I copied the original method signature incorrectly.

like image 575
Jeremy Avatar asked Aug 18 '10 15:08

Jeremy


1 Answers

I came across something like this a couple of years ago, COM does not support generics and so anything you expose to COM must be generics free.

In this case "int? iRange" is just shorthand for "Nullable<int> iRange" and as such causes the error. You may have to find another way to express whatever it is you use null to express. You could add another argument or use an otherwise unused value of iRange (0, -1 and int.MinValue come to mind as possibilities - I would recommend providing the value as a const if you choose this option).

like image 196
Brian Reichle Avatar answered Oct 19 '22 06:10

Brian Reichle