views:

605

answers:

1

Alright, I'm not sure if this question has been asked before so if it has then flame away. Lets say we have two classes like this

[Serializable]
public class ClassA
{
    private string _name;
    private ClassB _data;
}


public class ClassB : MarshalByRefObject
{
    public string GetAppDomainName()
    {
      return AppDomain.Current.FriendlyName;
    }  
}

As you can see ClassA holds a reference to ClassB but class B inherits from the MarshalByRefObject class. My question is when I attempt to pass ClassA to another AppDomain how can I get ClassA to serialize the way it normally would except pass the _data field over to the new AppDomain as a transparent proxy?

Any help is appreciated :)

+1  A: 

Have ClassA derive from MarshalByRefObject since it's the object you want to remote to the other AppDomain.

And you can implement ISerializable http://msdn.microsoft.com/en-us/library/system.runtime.serialization.iserializable.aspx

Types must inherit from MarshalByRefObject when the type is used across application domain boundaries, and the state of the object must not be copied because the members of the object are not usable outside the application domain where they were created.

Chad Grant
Normally that's what I would do however lets say that I don't have that option and that the object has to be serialized over and it has to contain a class that inherits from MarshalByRefObject.
Zerodestiny
What about wrapping ClassA in a wrapper class that derives from MashalByRefObject?
Chad Grant
you know, I think that might work. Thank you again!
Zerodestiny