In an attempt to pass data from a default (AppDomain.Current)
domain to a domain that gets created on the fly, I have came up with
the following code (a minimalistic example):
class Program
{
static void Main(string[] args)
{
AppDomain domain2 = AppDomain.CreateDomain("My Second Domain");
MyRemoteType remoteType = (MyRemoteType)domain2.CreateInstanceAndUnwrap
(Assembly.GetExecutingAssembly().FullName,
typeof(MyRemoteType).FullName);
MyData myData = new MyData();
remoteType.ModifyData(myData);
...
}
}
class MyData : MarshalByRefObject
{
public ArrayList _data = new ArrayList(); // Just an example
}
class MyRemoteType : MarshalByRefObject
{
public void ModifyData(MyData callerDomainData)
{
// [1] This doesn't modify the original MyData._data
callerDomainData._data.Add(new object());
// [2] This is an alternative that does modify
// the original MyData._data
ArrayList localReferenceToData = callerDomainData._data;
localReferenceToData.Add(new object());
callerDomainData._data = localReferenceToData;
}
}
I would appreciate any comments/explanations regarding the following
questions:
1. Why a direct access through a transparent proxy [1] doesn't work and,
perhaps more importantly, why does 'dereferencing' [2] work?
2. Are there any special considerations regarding the approach [2]? Is it
the only/good way to modify members of some type in another domain?
3. Are there any restrictions imposed on members of a
MarshalByRefObject-derived type that is meant to be passed as an
argument to another domain and modified there?
Should those members also implement (if possible) MarshalByRefObject?
I don't see why they should do so since the type's reference is all
that is needed to access its members (in this particular scenario, of
course), but still...
I think I've read somebody's explanation (I believe it was Eric Gunnerson)
but unfortunately I can't find it anymore.
In any case, thanks in advance for any clarification!
===================================
This list is hosted by DevelopMentorĀ® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com