HighTechTalks DotNet Forums  

InvalidCastException on instance creation

Dotnet Framework (Component Services) microsoft.public.dotnet.framework.component_services


Discuss InvalidCastException on instance creation in the Dotnet Framework (Component Services) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Gert Driesen
 
Posts: n/a

Default InvalidCastException on instance creation - 01-22-2004 , 03:48 AM






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.Meld ingService, received
Vmw.W8.CommunicationService.Business.Services.Hand TerminalCommunicationServi
ce.

Server stack trace:
at
System.EnterpriseServices.ServicedComponentProxyAt tribute.CreateInstance(Typ
e serverType)
at
System.Runtime.Remoting.Activation.ActivationServi ces.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



Reply With Quote
  #2  
Old   
AT
 
Posts: n/a

Default Re: InvalidCastException on instance creation - 02-18-2004 , 12:46 PM






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.
boris (AT) metratech (DOT) com

"Gert Driesen" <gert.driesen (AT) ardatis (DOT) com> wrote

Quote:
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.Meld ingService, received
Vmw.W8.CommunicationService.Business.Services.Hand TerminalCommunicationServi
ce.

Server stack trace:
at
System.EnterpriseServices.ServicedComponentProxyAt tribute.CreateInstance(Typ
e serverType)
at
System.Runtime.Remoting.Activation.ActivationServi ces.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

Reply With Quote
  #3  
Old   
Gert Driesen
 
Posts: n/a

Default Re: InvalidCastException on instance creation - 02-20-2004 , 02:19 AM




"Boris Partensky" <boris (AT) metratech (DOT) com> wrote

Quote:
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 ...

Quote:
This would be one possible reason.
How can that be a reason for this error ?

Thanks,

Gert




Reply With Quote
  #4  
Old   
AT
 
Posts: n/a

Default Re: InvalidCastException on instance creation - 03-07-2004 , 08:08 AM



Quote:
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


Reply With Quote
  #5  
Old   
Manni Javadi
 
Posts: n/a

Default RE: InvalidCastException on instance creation - 11-17-2009 , 04:56 PM



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/

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.