views:

1205

answers:

1

In .Net Activator.GetObject(Type type, string url, object data) returns a proxy to the object. I guess that proxy inherits from MarshalByRefObject and can be sent across AppDomains. Am I right?

In my app, I am creating an object in appdomain A and using it appdomain B. The object's members are proxyobjects created using Activator.GetObject (). so, when I am in AppDomain B, I have a transparent proxy to the object created in appdomain A. When I try to execute a call the method on the proxy objects, I am running into errors.

For Example, I Create a Connection object in App Domain B. I have the transparent proxy for the Connection object in App Domain A. I run in to error when I try to make a call like this from AppDomain A. ConnectionObject.SecurityProxy.GetSecurityAccount( ). looks like the problem is When I try to make a call like the one above, it is trying to create the SecurityProxy again in AppDomain A instead of forwarding the call to AppDomain B. The security proxy has already been created in AppDomain B when the connection object was created.

Could you please help me figure out what I am doing wrong?

Regards, Anil.

A: 

Assuming that SecurityProxy is a property on ConnectionObject...

You're dealing with the ConnectionObject proxy in domain A. Method calls are forwarded to domain B, where they are executed, and the results are returned to domain A.

A property is a compiler trick. It makes two methods, get_X and set_X, appear to be a field.

So, when you call "ConnectionObject.SecurityProxy" you are calling a method that returns an instance of SecurityProxy across the appdomain boundary.

You must do one of two things: Create and unwrap an instance of SecurityProxy and hand it to ConnectionObject, or turn ConnectionObject into a facade that only exposes methods and only returns types/takes arguments that you absolutely know are safe to cross appdomain boundaries.

Will
wow, old question.
Will