Share via


Isolated Storage and ClickOnce

Isolated storage introduced a new scope in v2.0 of the CLR to work with ClickOnce applications.  Application scoped Isolated storage is backed by the application's data directory.  This enables scenarios where your isolated storage data will flow forward with your application as ClickOnce updates it to new versions.

However, in order to take advantage of this, you need to be sure you're using the application scope.  The default IsolatedStorageFileStream constructor will actually use domain scope, even if you are running in a ClickOnce application.  (One design decision we could have made might have been to detect if this is a ClickOnce application and default to application scope, however this would lead to the situation where the program would have subtly different behavior if it was run as a standalone application.)

Since the default constructor is using domain scope, you might observe that as your application upgrades it appears that the files you stored in your isolated storage disappear.  Because of this behavior, you'll want to specify that you'd like to use application scoped storage instead of domain scoped storage:

IsolatedStorageFile scope = IsolatedStorageFile.GetUserStoreForApplication();
using(IsolatedStorageFileStream stream = new IsolatedStorageFileStream("data.dat", FileMode.OpenOrCreate, scope))
{
    // ...
}

Note that application scoped isolated storage is only available if your program is running as a ClickOnce application.  If it is not, you'll get an IsolatedStorageException when you call GetUserStoreForApplication which says "Unable to determine the application identity of the caller."

Comments

  • Anonymous
    January 18, 2006
    I'm just slightly confused. You state that "One design decision we could have made might have been to detect if this is a ClickOnce application and default to application scope, however this would lead to the situation where the program would have subtly different behavior if it was run as a standalone application.", but then go on to say that "Note that application scoped isolated storage is only available if your program is running as a ClickOnce application.", which means that the program itself must provide different behaviours depending on whether it's running as ClickOnce or Standalone, correct?

  • Anonymous
    January 18, 2006
    You have to start adding this type of very useful information to MSDN (for example on
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemioisolatedstorageisolatedstoragefilestreamclasstopic.asp)

    And Btw, when is Microsoft going to solve the current mess between msdn.microsoft.com and msdn2.microsoft.com (i.e. the documentation between 1.1 and 2.0)?

    Dinis Cruz
    Owasp .Net Project
    www.owasp.net

  • Anonymous
    January 19, 2006
    Damien,

    Yes, your program will have to provide different behaviors. However, in that case you will have the code for that right in front of you and it will be more easily discoverable than if it was hidden in a library somewhere.

    -Shawn

  • Anonymous
    January 19, 2006
    Dinis -- this should be documented on the msdn2 pages. I'm not sure what the doc team's plans are in regards to moving the msdn2 content onto the msdn servers.

    -Shawn

  • Anonymous
    January 19, 2006
    Shawn, have you received my other emails?

    I sent several emails to you which I never received any response, comment or acknowledge!

    Is this blog the only way to contact you?

    Dinis Cruz
    Owasp .Net Project
    www.owasp.net

  • Anonymous
    January 20, 2006
    I get a ton of email every day, and generally don't have the time to respond to most of the external mail I recieve (and still have time to work on the CLR! :-) ... generally when I do make time for community work, I like to work in the blog or on the forums where many people can benefit from the information rather than just one.

    If you've got a comment on one of my blog posts, then this is the right place to post it. If it's a general CLR question or comment then the Forums are a better location. (http://blogs.msdn.com/shawnfa/archive/2005/08/31/458507.aspx)

    -Shawn

  • Anonymous
    January 24, 2006
    Can you please send me the code on how to check if an application is running as a click-once application. You really need to do this so that you do not get the error you mentioned when you are running the application in the IDE (aka: debugging).

    shawn.mehaffie@umb.com

  • Anonymous
    January 27, 2006
    Sure thing ... check out http://blogs.msdn.com/shawnfa/archive/2006/01/20/514411.aspx for details on how to do that.

    -Shawn

  • Anonymous
    January 29, 2006

    Find
    Out What's New with Code Access Security in the .NET Framework 2.0
    and its
    side notes (MSDN...

  • Anonymous
    April 02, 2009
    what is the solution to "If it is not, you'll get an IsolatedStorageException when you call GetUserStoreForApplication which says "Unable to determine the application identity of the caller."? I am not using click-once.  I have a small utility program that I use for myself and I will never distribute it.  GetUserStoreForApplication will not work for me.

  • Anonymous
    April 27, 2009
    I am developing and deploying for testing a ClickOnce application on the same machine.  I am using Application scope for IsolatedStorage and do not have a problem running in the debugger (VS2005-VB).  (I assume it is because it was deployed to this machine.)  However, I cannot run it by double clicking on the exe.  How does the VB Host get around this?

  • Anonymous
    May 21, 2009
    I'm not sure, but one thing it may be doing is using an AppDomainManager to make the domain you're running in look like a ClickOnce domain. -Shawn

  • Anonymous
    May 26, 2009
    PingBack from http://backyardshed.info/story.php?title=net-security-blog-isolated-storage-and-clickonce