I have a static class which has some static data. What happens to the data if its accessed from different app domain?
Will there a copy of a static class for each domain?
Will the primitive types be copied?
What if the data is serializable?
I have a static class which has some static data. What happens to the data if its accessed from different app domain?
Will there a copy of a static class for each domain?
Will the primitive types be copied?
What if the data is serializable?
The memory between AppDomain's is not shared. By default the objects are a deep clone, if they are MarshalByRef then its similar to remoting where the calls are executed across AppDomain, so it appears that its shared state.
MarshalByRefObject
is the base class for objects that communicate across application domain boundaries by exchanging messages using a proxy. Objects that do not inherit fromMarshalByRefObject
are implicitly marshal by value. When a remote application references a marshal by value object, a copy of the object is passed across application domain boundaries.
I don't believe you can actually invoke static members using the AppDomain methods, your best bet would be to wrap the static calls in an instance class and use DoCallback
to execute that code in the other domain and collect the state in a MarshalByRef
object.
See the example on MSDN