views:

48

answers:

2

How can I determine whether an object is local or remote (using C# remoting)? Both checking in local code if the object is remote or in the object if the code is executed from remote would be okay.

A: 

I suppose you could look at the proxy and see if it derived from TransparentProxy

var myObj = ....;
if(myObj is TransparentProxy) 
  Console.WriteLine("I have a remote object");
else 
  Console.WriteLine("I don't think I have a remote object");
Preet Sangha
Could you tell me some more details on how to do that? TransparentProxy seems to be an internal class and, well, very *transparent*.
eWolf
+4  A: 
    if(System.Runtime.Remoting.RemotingServices.IsTransparentProxy(myObject))
      Console.WriteLine("Yay - my object is a remoted object.");
    else
      Console.WriteLine("Boo - my object is not a remoted object.");

MSDN Docs on IsTransparentProxy

brendan
I voted for this answer because it provides the MSDN documentation link about a specific FCL method, and I like to see the thoughts of the framework creators referenced. Other options might exist but Microsoft explicitly accommodated this method.
John K