broken cast operator

B

Ben Harper

I define an interface in managed C++: I call it ISgPlugin.
I implement that interface in a C# dll:
Using reflection, I try to load and instantiate that interface from the C++
module. I get far, but not far enough:

I use type->GetInterface( S"ISgPlugin" ) to get the type of a class inside
the C# dll that implements
ISgPlugin. That works.

I then use type->GetConstructor() to get an appropriate constructor for that
class. That works.

I invoke the constructor. That works. I now have an instance of the precise
class I am looking for: A class
derived from ISgPlugin- so the rest should be trivial.

I try and cast the instance I just created to ISgPlugin. That Fails.

I have absolutely no idea why this is. I have checked the C# dll in ildasm
and it appears fine- ie. it appears to implement ISgPlugin.
Everything else works, except for that last step. I am really dying for a
C-style cast here, but unfortunately that is no longer possible.
This looks to me like a bug in the compiler or runtime.
I have used the exact same method in a C# hosted dll, and it works
perfectly.

Anybody have any suggestions?
I am very very tired of this kind of thing.... I heard one MSFT
representative say recently at a conference, that they like implementing
features where one can say of it that "It Just Works". Well I am getting
pretty bloody tired of Managed C++, it seems too many parts of it "Just
Don't Work".

That said- I would love any help or suggestions.
.........
Ben.
 
B

Ben Harper

Please ignore this post.

My error was that I had my dll in the GAC, and two instances of it
were being loaded.
 

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