By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,864 Members | 1,069 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,864 IT Pros & Developers. It's quick & easy.

problem to cast object im getting from diffrent appdomain

P: n/a
first of all , PLEASE,say somthing..about my post.
any reply will be nice to read.

i have vb.app , with 2 appdomains.
(now, in the next section , ill write "appdomain create" ,means a code in
the appdomain is creating )

appdomain2 call appdomain 1 to create object of type "CCar" (the param is
string )
the appdomain1 creating a object from assembly file. ( the object is of
CCar type<< that inherits MarshalByRef )

the appdomain1 dont know the type of this object he just created , and keep
the instance in >>Object type<<.

appdomain1 sending back >>object type<< to appdomain2. (now, as i know,
because its between appdomains , a proxy is send)

now here is the PROBLEM:

appdomain2 , get the object of >>Object Type<< ,
and want to cast it to the real object type that is >> CCar Type <<.

when appdomain 2 try to cast the >>Object Type<< to >>CCar Type << , an
exception is throw of :

A first chance exception of type 'System.InvalidCastException'
occurred in MyAssembly.dll
Additional information: Specified cast is not valid.
now here is the code sample in appdomain 2:

------------------------------
dim obj as object
dim myCar as CCar

obj = m_someObjectInAppdomain1.CreateThisClass ( "CCar")

myCar = CType(obj , CCar) // throw 'System.InvalidCastException'

------------------------------

can someone explain what im missing here ?
and how can i cast an object i recive from other appdomain ?

hope this clear.if not ,pls ask and explain any details.
im try to solve this problem for 2 day.

bye.
Jul 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.