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?
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.
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.
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 2012-04-04 20:29