Interop problems from C# to VB

  • Thread starter Thread starter Doug
  • Start date Start date
D

Doug

I am working on an existing .NET (C Sharp) component that had a com
interface that was used by a VB component. When it was originally
written, it had a class with 12 methods that inherited from that
interface. I needed to add two new ones. I was told I would need to
create a secondary interface
that the class would use which I've done. I cannot get VB to
recognize both the new and old methods in any situation I've tried. I
have tried the following scenarios to no avail. Can someone help
here?

1) Tried with just the old interface with 12 methods and got rid of
my two new ones - this worked just fine but since I need the new
ones...:)

2) Added two new methods to old interface - old methods worked, new
ones caused "Object doesn't support this property or method" error.

3) Left old interface with two new methods - changed the guid -
caused "Type Mismatch" error when object was being created.

4) Created new interface with two new methods, had my class inherit
from both the old and new interface - VB does not show the new methods
in intellisense and trying to call them causes "Object doesn't support
this property or method" error (interestingly enough if I change my
class to inherit from the new class first and the old class second,
then the old methods don't show up in intellisense, the new ones do).

5) In new interface, had it inherit from old interface and had my
class inherit just from new interface - VB does not show the old
methods in intellisense and trying to call them causes "Object doesn't
support this property or method" error.

6) In old interface, had it inherit from new interface - VB does not
show the new methods in intellisense and trying to call them causes
"Object doesn't support this property or method" error.

7) In new interface, removed inheritance from old interface - put
methods from old interface in new interface, had class inherit from
new interface only. VB shows all methods in intellisense, but throws
"Object doesn't support this property or method" error when calling
old methods. New method calls work just fine.

8) Kept new and old interface, had class inherit from old interface.
Created brand new class and had it inherit from new interface. Create
a seperate object in VB to call new methods that would use new class
from C# code. When object attempted to get created got the error:
"Could not load type PLXX0005.SSEAssemblyCom2 from assembly PLXX0005.
PLXX0005.SSEAssemblyCom2"
 
Doug,

What I would do is just add the methods to your class, and then remove
the reference to the original C# dll from the VB project. Once you do that,
re-add the reference, and re-compile the VB project.

In order to get around this, you should not be exposing the class
methods as the interface to the class. Rather, you should define an
interface, and then implement the interface on the class. When you bind to
the class, you will actually cast it to the interface that the class
implements.

When you need to add methods, create a new interface, and implement that
on the class as well. Then, all you have to do is declare your references
as the new interface type, and make the call.

Hope this helps.
 
Back
Top