Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Component Services / March 2004

Tip: Looking for answers? Try searching our database.

InvalidCastException on instance creation

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gert Driesen - 22 Jan 2004 09:48 GMT
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 - 18 Feb 2004 18:46 GMT
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@metratech.com

> Hi,
>
[quoted text clipped - 22 lines]
>
> Gert
Gert Driesen - 20 Feb 2004 08:19 GMT
> 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 - 07 Mar 2004 14:08 GMT
> > Hi Gert!
> > Are you by any chance using your serviced components (in particular
[quoted text clipped - 6 lines]
>
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.