473,385 Members | 1,518 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

[Q] Cast remote object to a local object

Tao
hi. guys,

I have two AppDomains, AppDomain0 and AppDomain1. In AppDomain1, I got a
class implements an interface IInterface0. In AppDomain0, I also define a
IInterface0, the code of two interfaces are exactly same.

When I call:

appDomain.CreateInstanceFromAndUnwrap and try to convert to
AppDomain0.IInterface0. I got an error.

I was wondering why? Their codes are exactly same. Is there any way that I
can do such cast?

I hope I explain this problem clearly.

thanks, guys
Nov 8 '06 #1
3 1359
Hello, Tao!

Its hard to tell the answer without additional information. Can
you post a small code sample, where you define
interfaces and try to convert them?

You wrote on Wed, 8 Nov 2006 10:54:02 -0800:

Thi. guys,

TI have two AppDomains, AppDomain0 and AppDomain1. In AppDomain1, I
Tgot a
Tclass implements an interface IInterface0. In AppDomain0, I also
Tdefine a
TIInterface0, the code of two interfaces are exactly same.

TWhen I call:

TappDomain.CreateInstanceFromAndUnwrap and try to convert to
TAppDomain0.IInterface0. I got an error.

TI was wondering why? Their codes are exactly same. Is there any way
Tthat I
Tcan do such cast?

TI hope I explain this problem clearly.

Tthanks, guys

--
With best regards, Vadym Stetsyak.
Blog: http://vadmyst.blogspot.com
Nov 8 '06 #2
Tao
Hi.. Vadym,

The code is something like:

In AppDomain0, I define:
public interface IA { void M(); }

In AppDomain1, there is a interface defined:
public interface IA {void M(); } //exactly same as IA in AppDomain0
public class A : IA {... } //class A implements IA
I compiled A.dll which contains IA and A.

The following program does:

0. launch the main program running in AppDomain0. Main program has a IA
interface defined.
1. create a new AppDomain, AppDomain1
2. load the A.dll into AppDomain1
3. Create a remote object and try to convert it to IA.

AppDomainSetup setup = new AppDomainSetup();
setup.ApplicationBase = this.path;
setup.PrivateBinPath = AppDomain.CurrentDomain.BaseDirectory;
setup.ApplicationName = "A.dll";
setup.ShadowCopyFiles = "true";
setup.ShadowCopyDirectories = AppDomain.CurrentDomain.BaseDirectory;
AppDomain appDomain = AppDomain.CreateDomain("A", null, setup);
IA a = (IA)appDomain.CreateInstanceFromAndUnwrap(fileName , "A"); //Error!

Compile is fine. When I run the program, it complains about not being able
to cast a transparent proxy to type IA.

thanks again.

"Vadym Stetsyak" wrote:
Hello, Tao!

Its hard to tell the answer without additional information. Can
you post a small code sample, where you define
interfaces and try to convert them?

You wrote on Wed, 8 Nov 2006 10:54:02 -0800:

Thi. guys,

TI have two AppDomains, AppDomain0 and AppDomain1. In AppDomain1, I
Tgot a
Tclass implements an interface IInterface0. In AppDomain0, I also
Tdefine a
TIInterface0, the code of two interfaces are exactly same.

TWhen I call:

TappDomain.CreateInstanceFromAndUnwrap and try to convert to
TAppDomain0.IInterface0. I got an error.

TI was wondering why? Their codes are exactly same. Is there any way
Tthat I
Tcan do such cast?

TI hope I explain this problem clearly.

Tthanks, guys

--
With best regards, Vadym Stetsyak.
Blog: http://vadmyst.blogspot.com
Nov 8 '06 #3
Tao
Thanks Vadym,

I figured out what's going on.

"It forms a type boundary. Every type's identity includes the name of the
assembly in which it resides. A type called MyType loaded in the scope of one
assembly is not the same as a type called MyType loaded in the scope of
another assembly."

So even codes are exactly same, their assembly name is different. Therefore,
I cannot cast from one type to another.

Thanks.. :)

"Vadym Stetsyak" wrote:
Hello, Tao!

Its hard to tell the answer without additional information. Can
you post a small code sample, where you define
interfaces and try to convert them?

You wrote on Wed, 8 Nov 2006 10:54:02 -0800:

Thi. guys,

TI have two AppDomains, AppDomain0 and AppDomain1. In AppDomain1, I
Tgot a
Tclass implements an interface IInterface0. In AppDomain0, I also
Tdefine a
TIInterface0, the code of two interfaces are exactly same.

TWhen I call:

TappDomain.CreateInstanceFromAndUnwrap and try to convert to
TAppDomain0.IInterface0. I got an error.

TI was wondering why? Their codes are exactly same. Is there any way
Tthat I
Tcan do such cast?

TI hope I explain this problem clearly.

Tthanks, guys

--
With best regards, Vadym Stetsyak.
Blog: http://vadmyst.blogspot.com
Nov 8 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Brent | last post by:
I maintain a Sql Server database application whose forms are compiled in a .dll and kept in a remote web folder. The main .exe looks to the web folder to see if this .dll exists. If so, then it...
11
by: Alberto Giménez | last post by:
Hi, I've seen some object oriented programming bits out there and i'm not sure if they're legal. For example: struct Object { int field1; int field2; }; struct SubObject { int field1; /*...
0
by: Daylor | last post by:
how can i cast remote object ? if i have remote object to type Cbase that holds CDerived object. how can i cast in the client from CBase To CDerived ?
3
by: John Howard | last post by:
Making the following call to a local MSAccess database works fine: Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) Dim intRows As Integer Dim strSQL As String Dim ds As New...
5
by: felecha | last post by:
I have a VB.Net application that runs as a Windows Service and monitors a MessageQueue on another machine. At times that machine will have to be rebooted, so I've been working on how to get my...
21
by: John Howard | last post by:
Making the following call to a local MSAccess database works fine: Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) Dim intRows As Integer Dim strSQL As String Dim ds As New...
2
by: Julia | last post by:
Hi, Can a Remote object be a WebService as well? i want to able to connect to a remote object either using .NET remoting and HTTP\SOAP so I wonder if I can create a singleton(statefull)...
3
by: ist | last post by:
Hi, I am trying to get (and transfer over ASP.NET) some encrypted data from some MySQL fields. Since the data contains many unicode characters, I tried to get the data as a series of ASCII...
5
by: Cirene | last post by:
I just deployed my new ASP.NET (3.5 FW) site to the hosting company I'm using, webhost4life. NOTE: I HAVE deployed other SQL Server sites to the same account with no issues. Now I'm getting...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.