I have a program in which I am creating two appdomains A and B . I want to share a dictionary between them. Basically I am creating the dictionary in appdomain A. At this stage, for each key in the dictionary the value part is initialized to null. Then appdomain B needs to access this dictionary and fill in the values for the corresponding keys. After this, A will use the updated dictionary. Could someone please tell me how can I go about doing this. It would be great to have a very small sample example outlining the procedure. Thanks in advance
Asked
Active
Viewed 1,721 times
2 Answers
0
You cannot share an object between two appdomains. Have a look at .net Remoting or WCF if you need to share data between two or more appdomains.

Dominik
- 3,342
- 1
- 17
- 24
-
Ok, then is there a way I can pass the dictionary data between the two appdomains? Could you please provide some guidance for that – Manan Shah Aug 31 '11 at 13:23
-
@Manan Shah: Check the following thread http://stackoverflow.com/questions/50153/interprocess-communication-for-windows-in-c-net-2-0 – Dominik Aug 31 '11 at 13:27
0
I don't know much about sharing across AppDomains but have you tried AppDomain.SetData()
and AppDomain.GetData()
? If that doesn't work, everyone else pretty much says use WCF or if your project is older then Remoting.

Community
- 1
- 1

Chris Haas
- 53,986
- 12
- 141
- 274
-
Using SetData() would require you to have a reference to the appdomain, something you can only acquire in the appdomain where you spawned the "child" appdomains, so I think this wouldn´t help here. – Dominik Aug 31 '11 at 13:35
-
@Chris: I did try the SetData/GetData method but it didn't work for me. When I do a GetData my dictionary count is showing zero :( – Manan Shah Aug 31 '11 at 13:41
-
@Dominik : I do have reference to the appdomain but I am facing the problem which I mentioned above – Manan Shah Aug 31 '11 at 13:42
-
@Manan Shah: Where do you call SetData()? I suppose you´re trying to call SetData() in domain A and then GetData in domain B, this will not work. When you start your application, your first appdomain is created without you doing anything. Then you start domains A and B. Only from the first domain you could call Setdata() on a reference to appdomain A and retrieve the data inside domain A. – Dominik Aug 31 '11 at 13:47
-
@Dominik: My default domain is the Domain A. So what I am doing right now is inside domain A, I am doing B.SetData and then in the domain B, I am doing currentDomain.GetData. But I am getting the dictionary count as 0. Thanks for your help – Manan Shah Aug 31 '11 at 14:03
-
@MananShah: What is inside your dictionary? If I remember correctly whatever you want to share using SetData has to be [Serializable] – Dominik Aug 31 '11 at 14:09
-
@Dominik: My dictionary contains string, double as the key value pair – Manan Shah Aug 31 '11 at 14:12
-
@MananShah Sorry but I have to less information to help you from here. Concerning the SetData issue I´d suggest you open a new question, although I´d recommend you´d follow the WCF approach. – Dominik Sep 01 '11 at 06:25