Interop problem: Specified cast is not valid

C

coenve

We use ActiveX control to render images server-side in code-behind.
Reference is added to the project, Interop assembly is created, project
compiles, builds, all's fine. All files are moved to the testserver, ocx
that hosts the control that's interoped is registered with regsvr32. On the
line that creates the object:

obj = (MyLib.chart)Server.CreateObject("MyLib.chart");

Server throws an exception: System.InvalidCastException: Specified cast is
not valid.

Control is registered correctly, as I can see it clearly in OleView. The
only thing that I can think of is that somehow what CreateObject returns is
not the type that Interop says it should be. I've read that if 2 developers
create interop for one COM object, those 2 resultant interops will not be
type-compatible, which rings my bell because of 'cast not valid' exception,
however I have just one interop file here.

I would be glad to hear any suggestions, i'm a bit stuck with this.
 
G

Guest

You can get messed up between COM and .NET with mismatching integers and
longs. Passing the wrong one can cause a problem. Try using some Try...Catch
in there to see if there's an inner exception that you can get at for more
information.
 

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

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top