0
votes

I don't know much about Com Plus Interop services in .NET - I let .NET do all the dirty work and I cross my fingers it'll work. Well, now I'm stuck.

I've got a reference to a COM DLL compiled with VB6 in my VS 2010 C# program. This is an invoice I'm creating.

I instantiate an object:

UIInvoice Invoice = new CUIInvoice();

And then I set some invoice header properties:

Invoice.set_InvoiceType("VO");
Invoice.set_InvoiceTypeID(2);

And now, I want to create some invoice detail lines, which I do by calling the add method of a child object of the invoice:

Invoice.InvoiceDetails.Add("StringParam1", "StringParam2", Invoice);

The third parameter of the function call is defined in my VB6 Add function as:

ByRef Parent As Object

When I run my .NET program, I get a "type mismatch" error when I hit the Add line.

Can anyone suggest, in simplistic terms, a way I can get this to work?

2
You would normally write ref Invoice in C#. Guess you're using C# version 4. Nothing else is obvious, it just doesn't like CUIInvoice to be a parent. Maybe because of "UI".Hans Passant
Hi Hans, thanks for your reply. When I pass the Invoice object by ref, I actually have a compiler error - which may be a clue to those with more knowledge: cannot convert from 'ref UIInvoice.CUIInvoice' to 'ref object'. If I declare a static object type as in object temp = Invoice; and pass temp in by ref, I get the same type mismatch error.user529703
What is the difference between UIInvoice and CUIInvoice? What happens if you declare Invoice as: CUIInvoice Invoice = new CUIInvoice();?Tim Lentine

2 Answers

0
votes

My recommendation would be to not fool around with COM, but migrate the VB6 code to Visual Basic.NET. You'll have much less problems marshalling objects back and forth with C#. If this object is shared with other legacy applications, you may be able to create a COM wrapper that maintains your legacy compatibility as well. Obviously you need to weigh this against your business requirements.

0
votes

If you own the VB6 source then I suggest changing the definition of Add to be ByVal instead of ByRef. There is almost never a reason to use ByRef object references in VB6, and from the tiny bit I am gleaning from your code, you don't need to to associate paranet/child relationships in your domain objects.