views:

428

answers:

2

I've edited and trimmed this to try and get it closed because the site is prompting me to accept an answer or add a bounty.

I did an experiment which had calls to GetUserStoreForAssembly and GetUserStoreForDomain in a library referenced by a console app but didn't understand why I was getting more stores than I expected in one case and less in another.

Preet helped me tune my experiment and I ended up with two slightly differnt issues:

  • when I copied the console app to another directory (so the name remained the same), I got two user/assembly stores i.e. one per copy when I expected them to share

  • when I loaded my library into multiple domains within the console app they all still used the same user/assembly/domain store when I expected them to not share

By then, the question was cold. I did my own reading and I thought I found the answers so answered the question myself hoping someone would confirm/correct. But it was so far down the list there was no chance. I was just going to leave it but then got prompted to accept or add bounty.

So I've moved my answer here and now just need someone to add some helpful comment either confirming or correcting so I can accept it and know that this will actually be useful to anyone else wanting to better understand isolated storage:

Possible answer to first question:

Strong named assemblies are of course identified by their strong name. Weakly named (not sure if that's an official term but whatever) are identified by their URL or file location. So the same weakly named assmebly copied to a different directory will have it's own separate isolated store.

Possible answeranswer to second question (less certain about this one):

The scope returned by GetUserStoreForDomain is restricted to the machine, user, application and assembly, specifically that assembly running within a specific application.

My experiment created multiple additional domains but they are all in the same application. Therefore, they are all using the same domain store.

Therefore, to simulate domain isolation, I actually need to reference the library from two different console applications.

And this will only work properly if the library (and hence both console applications) are strong named. Referencing an assembly results in it being copied meaning if it's weakly named it will have a seperate isolation store.

I just tried the whole experiment out with strong naming I now get 2 domain stores and 1 assembly store as expected.

+2  A: 

You can create multiple app domains in a single program/process. Inside the appdomain you can load the assembly. The call the methods in each app domain/assembly

There are examples here (appdomains) and here (AssemblyIdentity) and here

Preet Sangha
Ah. I must have been tired yesterday or something. It didn't occur to me I could just create them myself. Any chance you can also help me with teh first question? Whenever I google for assembly identity I see stuff about version, culture, etc. But nothing to do with location of the actual file...
J M
I'm pretty certain Assembly Identity will be based on strong name. Isolated storage will be creating subfolders based some function of this strong name. I'm added another link.
Preet Sangha
Feel free to contact me privately if you want I'll see if I can help.
Preet Sangha
Hi again, I've been playing with creating app domains using the link you posted (which has been very interesting) but I still cannot properly demonstrate domain isolation. I am about to update my question with the experiment and code if you are interested at all.
J M
Used that link and reflector - ended up in private method in IsolatedSTorage called _GetAccountingInfo. Takes evidence and a scope and checks publisher, strong name, url, site, zone in that order. I think this means my copies will be detected as diff assemblies if they are not strong named....
J M
Closing an old question - didn't realise it was still open. Thanks for the help.
J M
A: 

You can create multiple app domains in a single program/process. Inside the appdomain you can load the assembly. The call the methods in each app domain/assembly

There are examples here

Preet Sangha