Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

InvalidCastException on instance creation

199 views
Skip to first unread message

Gert Driesen

unread,
Jan 22, 2004, 4:48:52 AM1/22/04
to
Hi,

After a few days of operation, we sometimes get an InvalidCastException on
the creation of an instance of a COM+ library-type component (written in C#)
:

Exception: System.InvalidCastException
Message: CoCreateInstance returned an unexpected type: expected
Vmw.W8.CommunicationService.Business.Services.MeldingService, received
Vmw.W8.CommunicationService.Business.Services.HandTerminalCommunicationServi
ce.

Server stack trace:
at
System.EnterpriseServices.ServicedComponentProxyAttribute.CreateInstance(Typ
e serverType)
at
System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(Typ
e serverType, Object[] props, Boolean bNewObj)
....

We're using Windows 2000 Service Pack 4 and .NET Framework 1.1.

Anyone have a clue as to what might be causing this ? Is this a known issue
for Enterprise Services (COM+) ?

Gert


Boris Partensky

unread,
Feb 18, 2004, 1:46:41 PM2/18/04
to
Hi Gert!
Are you by any chance using your serviced components (in particular
MeldingService or HandTerminalCommunicationService types) as instance
variables in your classes? This would be one possible reason.

Hope this helps.
bo...@metratech.com

"Gert Driesen" <gert.d...@ardatis.com> wrote in message news:<e#uZ2zM4...@TK2MSFTNGP11.phx.gbl>...

Gert Driesen

unread,
Feb 20, 2004, 3:19:41 AM2/20/04
to

"Boris Partensky" <bo...@metratech.com> wrote in message
news:e0b75b63.04021...@posting.google.com...

> Hi Gert!
> Are you by any chance using your serviced components (in particular
> MeldingService or HandTerminalCommunicationService types) as instance
> variables in your classes?

Definitely, they both are ...

> This would be one possible reason.

How can that be a reason for this error ?

Thanks,

Gert


Avner Kashtan

unread,
Mar 7, 2004, 9:08:51 AM3/7/04
to
> > Hi Gert!
> > Are you by any chance using your serviced components (in particular
> > MeldingService or HandTerminalCommunicationService types) as instance
> > variables in your classes?
>
> Definitely, they both are ...
>
> > This would be one possible reason.
>
> How can that be a reason for this error ?

I seem to be having a similar problem here.
I instantiate a ServicedComponent inside my class and assign it to an
instance variable, and get an InvalidCastException pointing to a
completely unexpected class. Something like this:


Class2 : ServicedComponent, IInterface
{
}

Class1 : ServicedComponent
{
IInterface obj;

public myMethod ()
{
obj = new Class2(); // This is where I get the exception.
}
}

The exception I get is:
InvalidCastException: Expected Class2, recieved Class1.

I find it very strange for several reasons:
1) Why would it receive Class1, since this code is called INSIDE
Class1?
2) It says "Expected Class2", even though my instance member is
defined as IInterface, not Class2.
3) All this happens in my testing environment, but not in the
development environment. Same DLLs, theoretically.

All this code is server-code being called by Remoting with another
Facade layer calling the Class1 first, just in case it matters.

Hope I was understandable, and I hope this gets clarified.

TIA,
Avner Kashtan

Manni Javadi

unread,
Nov 17, 2009, 5:56:30 PM11/17/09
to
Probably you registered remoting for HandTerminalCommunicationService, in this case, the MeldingService also needs to be registered as RemotingConfiguration.RegisterWellKnown ...

Hope this works.


From http://www.developmentnow.com/g/19_2004_1_0_0_100926/InvalidCastException-on-instance-creation.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com/g/

0 new messages