Question

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 :)

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top