Cannot convert from object class to object

S

shel

Hi All,
Probably a silly question to those who know, but i'm a noob with C# :D

I have a COM component written in VB6 I'm trying to interop to from C#
(using the IDE 'Add Reference' capability to register the component).
Some functions work ok, but I have one function that takes a class
from the component and passes it to another function in a different
class within the same component. So in my C# application, I have a
call that looks something like :

m_oBusinessUnit.Init (m_oWorkstation)

The problem I have is that when C# registers the COM object for C#
interop compatibility, it creates the original Workstation class as
WorkstationClass, and the declaration in the VB COM component is
expecting just plain old Workstation as a parameter. So when I declare
m_oWorkstation in the C# app as a WorkstationClass object, there's a
conversion error when calling the Init function of the m_oBusinessUnit
class.

Any help would be greatly appreciated.

Regards
-Shel
 
G

Guest

but I have one function that takes a class
from the component and passes it to another function in a different
class within the same component. So in my C# application, I have a
call that looks something like :

m_oBusinessUnit.Init (m_oWorkstation)

My COM interop is getting a bit rusty but...

1) Are you sure you don't mean "interface" instead of class? The .Init() method takes an interface reference - yes? - not a class reference? If it takes a class reference then you can shoot the VB6 component developer for breaking the rules... I dunno if you can do anything in this situation...

2) I think when you import the component the importer generates an Interop assembly with an XxxxClass for each Xxxx interface. The XxxxClass thingy is used to instantiate the interface for you using your language's "new" syntax ala:

Xxxx xxx = new XxxxClass();
xxx.MethodCall();

so check to see that you don't have a lollipop interface with the correct name - if you do then try passing that to the .Init() function...

3) If this is a genuine name collision there is a way to rename things - I think it's an Attribute like [ImportAs XXxxx] or [Rename Xxxx] something like that...

Hope it helps...

--Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top