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?
A simple porgram which prints 0,1,2 and 0,1,2 which shows the appdomain doesnt share static data.
Just modified one of: Static Fields in AppDomain
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.
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 aMarshalByRef
object.See the example on MSDN
You have to deliberately load the static class in each app domain in order to access it, for each app domain it will maintain its own static data.
check this: Static Fields in AppDomain
In general you will have a copy of data and separate initialization per appdomain.
If this is a specific question, you might want to share an example of what you are doing. There are marshalling scenarios that will copy data.
This post is quite complete: http://blogs.msdn.com/b/cbrumme/archive/2003/06/01/51466.aspx
It states:
And I agree.