Partilhar via


Reflection and remoting

Reflection should work just fine over remoting proxies. In some cases you need to be a little careful since for some cases the entire type heirarchy isnt available mainly for wellknown proxies, since the proxy is generated without a remote invocation, and only has type information it was bound to: for example if the following code

     IFoo foo = (IFoo)RemotingServices.Connect(typeof(IFoo), "tcp://foo.com/remoteobject.rem");

the foo proxy only has type information for IFoo and MarshalByRefObject (since all proxied objects need to be inherited from MBR). Thus foo.GetType() will return MarshalByRefObject instead of Foo which might be implementing IFoo on the server side. Thus you would be unable to reflect over foo.GetType() in any significant way. typeof(foo) will get you a little closer since the type returned would be IFoo.

Things will work a little better for client-activated proxies as most type hierarchy is carried with the ObjRef which is the serialized form of a MBR. Thus casts to types in the server hierarchy are handled better.