Create an IsolatedStorageFileStream that can be shared between applications. RRS feed

  • Question

  • I'm trying to read/write an isolated storage file in a class library that will be shared by 2 applications. I can't use IsolatedStorageFile.GetUserStoreForAssembly() since it will return the application's store...not the library's. Similary, GetUserStore(<scope>, null, null) will return different stores when called from different applications. I've tried different versions of Evidence constructors like this:

    Assembly assembly = Assembly.GetAssembly(this.GetType());
    Hash hash = new Hash(assembly);
    EvidenceBase[] arrObj = new EvidenceBase[1];
    arrObj[0] = (EvidenceBase)hash;
    Evidence assemblyEvidence = new Evidence(arrObj, arrObj);
    Evidence domainEvidence = new Evidence(assemblyEvidence);
    IsolatedStorageFile store =
       IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly,      null, typeof(System.Security.Policy.Hash),
       assemblyEvidence, typeof(System.Security.Policy.Hash));
    oStream = new IsolatedStorageFileStream(IsoFileTester.ISOLATED_FILE_NAME,    FileMode.Create, FileAccess.ReadWrite, store);

    ...which lets me instantiate an IsolatedStorageFile, but when I try to instantiate the IsolatedStorageFileStream, I get an IsolatedStorageException with the message: Allowed quota is fully used.

    Why is the quota fully used (the stream can never be instantiated)? What is the correct way to have 2 applications share the same isolated storage of a class library?

    Tuesday, September 4, 2012 5:38 PM


All replies

  • Hi D-Caveney,

    Welcome to the MSDN Forum.

    What is your VS version and the .net framework version based on?

    And what is your other development environment?

    Thank you.

    Best regards,

    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, September 5, 2012 7:50 AM
  • Maybe this thread can help: http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/5049635e-35bf-4821-b851-dcbec1535a06

    Or maybe the application has no permission:

    Note If the scope parameter is Domain and the application domain in which the assembly is installed does not have IsolatedStorageFilePermission, the GetStore method will return an IsolatedStorageFile object without a quota. Later attempts to create an IsolatedStorageFile object using the IsolatedStorageFile object that does not have a quota will fail with an IsolatedStorageException

    • Proposed as answer by Mike Feng Thursday, September 6, 2012 2:11 AM
    • Marked as answer by Mike Feng Monday, September 24, 2012 2:38 PM
    Wednesday, September 5, 2012 8:14 AM
  • Hi, 

    Thanks for responding. I'm working with VS 2010 Professional and the framework is .Net Framework 4.

    Wednesday, September 5, 2012 1:46 PM
  • @boothwine:

    The thread DID  help. When I used static methods as described in the thread everything worked beautifully and "machine" scope will be ok for what I need. The strange thing is, if I make the 

    IsolatedStorageFile object a private member of a class (like IsoHelper in the example), and then try to make IsolatedStorageFileStream objects from it in subsequent non-static methods, one application will write to one file and the other will read from a different one. But again, static methods will be ok for what I need and is probably what I should have done in the first place!

    Thanks everyone for all the help.

    Wednesday, September 5, 2012 3:21 PM
  • Oh boy, starting to feel stupid. GetUserStoreForAssembly() works fine also when called from within static methods.

    I'd still be interested in seeing an example using GetStore() with evidence and all that though.

    Wednesday, September 5, 2012 5:39 PM
  • Nice to know. I wouldn't have guessed that. It seems strange to work only correct with static functions...
    Thursday, September 6, 2012 12:36 PM
  • Well, I don't think it's because the methods were static, but originally I had a class in the class library that instantiated and kept an IsolatedStorageFile object as a member. The calling applications would instantiate this class, and invoke its methods and the class would read/write through it's IsolatedStorageFile member (which wasn't good because we never "finalized" the store). I suppose the assembly behind the store became the application's assembly instead of the library's assembly since the app instantiated the object that instantiated the IsolatedStorageFile? By using static methods from the library the scope could only be the library's assembly.
    Thursday, September 6, 2012 7:19 PM
  • Hi Boothwine,

    Do you forget this case? I also want to learn something from this thread. Thank you very much.

    Have a nice day.

    Call me ghost for short, Thanks
    To get the better answer, it should be a better question.

    Monday, September 10, 2012 6:18 AM