Welcome to MSDN Blogs Sign in | Join | Help

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."

Published Wednesday, January 18, 2006 10:29 AM by shawnfa
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Isolated Storage and ClickOnce

Thursday, January 19, 2006 2:30 AM by Damien
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?

# MSDN

Thursday, January 19, 2006 6:33 AM by Dinis Cruz
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

# re: Isolated Storage and ClickOnce

Thursday, January 19, 2006 11:25 AM by shawnfa
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

# re: Isolated Storage and ClickOnce

Thursday, January 19, 2006 11:26 AM by shawnfa
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

# My Other emails

Thursday, January 19, 2006 7:04 PM by Dinis Cruz
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

# re: Isolated Storage and ClickOnce

Friday, January 20, 2006 7:34 PM by shawnfa
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

# re: Isolated Storage and ClickOnce

Tuesday, January 24, 2006 11:32 AM by Shawn Mehaffie
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

# re: Isolated Storage and ClickOnce

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

-Shawn

# Partial Trust and Click Once

Monday, January 30, 2006 7:08 AM by Dinis Cruz @ Owasp .Net Project

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

# re: Isolated Storage and ClickOnce

Thursday, April 02, 2009 4:06 PM by matt

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.

# re: Isolated Storage and ClickOnce

Monday, April 27, 2009 10:52 PM by Stewart Berman

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?

# re: Isolated Storage and ClickOnce

Thursday, May 21, 2009 5:20 PM by shawnfa

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

# NET Security Blog Isolated Storage and ClickOnce | Shed Kits

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker