IsolatedStorageException: Unable to create the store directory

Hi I have to store some hidden information in Isolated space. For that I am using System.IO.Isolated class like

IsolatedStorageFile isf =     System.IO.IsolatedStorage.IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null);
Stream writer = new IsolatedStorageFileStream(filename, FileMode.Create, isf);

IFormatter formatter = new BinaryFormatter();
formatter.Serialize(writer, appCollection.ToString());

writer.Close();

It works fine in Windows XP but on production server that is windows 2003 it shows exception

System.IO.IsolatedStorage.IsolatedStorageException: Unable to create the store directory.

I have a Everyone full control permissions in my asp.net project folder. Attention CSoft.Core is a personal Framework created by me.

This is my Stack Trace:

[IsolatedStorageException: Unable to create the store directory.
(Exception from HRESULT: 0x80131468)]
System.IO.IsolatedStorage.IsolatedStorageFile.nGetRootDir(IsolatedStorageScope
scope) +0
System.IO.IsolatedStorage.IsolatedStorageFile.InitGlobalsNonRoamingUser(IsolatedStorageScope
scope) +97
System.IO.IsolatedStorage.IsolatedStorageFile.GetRootDir(IsolatedStorageScope
scope) +137
System.IO.IsolatedStorage.IsolatedStorageFile.GetGlobalFileIOPerm(IsolatedStorageScope
scope) +213
System.IO.IsolatedStorage.IsolatedStorageFile.Init(IsolatedStorageScope
scope) +56
System.IO.IsolatedStorage.IsolatedStorageFile.GetStore(IsolatedStorageScope
scope, Type domainEvidenceType, Type assemblyEvidenceType) +59
CSoft.Core.IO.StorageHelper.Save(String fileName, String content) in
c:ProjectosFrameworkCSCSoft.CoreIOStorageHelper.cs:18
CSoft.Web.UI.ViewStateHelper.SerializeViewState(HttpContext context,
Object state) in
c:ProjectosFrameworkCSCSoft.Web.ControlsWebUIViewStateHelper.cs:65
CSoft.Web.UI.Page.SavePageStateToPersistenceMedium(Object state) in
c:ProjectosFrameworkCSCSoft.Web.ControlsWebUIPage.cs:302
System.Web.UI.Page.SaveAllState() +236
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+1099

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

If it’s running on IIS and application pool identity is NetworkService, You can try to go to advanced settings of application pool and set “Load user profile” value to “True”. Worked for me.

Method 2

I know this user solved their problem already, but for others looking for an answer. This post is not perfect, but it will point you to what you need to solve this problem.

With asp.net GetMachineStoreForAssembly seems to work in most cases, and it probably the desired mode when using isolated storage from a web app. Because even if you use GetUserStoreForAssembly, it will be isolated by the user account running the asp.net app and it will always be the same for each website user, unless you are somehow mapping each login to an windows user(oh and if you are doing this then it would be working).

The problem is then you try to use GetUserStoreForAssembly because it needs a user with rights to isolated storage, the default IIS user for applications do not get rights for this I guess.

There are 2 solutions:

  1. use GetMachineStoreForAssembly
  2. If you must use GetUserStoreForAssembly set the App to run as user with rights. This is not solved by folder permissions. There are several ways to get security setup.(IIS7) You can set it on the App pool, or under basic settings > Connect As, or under Authenication > Anonymous Authenication. I am not sure exactly what rights the user needs, but this will get you going in the right direction.

Here is some bonus code than may help you figure out your problem:

   Dim storageFile As IsolatedStorageFile
    If Request("storage") = "user" Then
        storageFile = IsolatedStorageFile.GetUserStoreForAssembly()
    Else
        storageFile = IsolatedStorageFile.GetMachineStoreForAssembly()
    End If

    Response.Write(storageFile.GetType.GetField("m_RootDir", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance).GetValue(storageFile).ToString())

GetUserStoreForAssembly is here:
C:Documents and SettingsGabeLocal SettingsApplication DataIsolatedStorage

GetMachineStoreForAssembly is here:
C:Documents and SettingsAll UsersApplication DataIsolatedStorage

Method 3

I changed IsolatedStorage file to

using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetMachineStoreForAssembly())
{ }

And this work.

Method 4

How are you running this on the server? If you’re running it as a service on the server, you may have a problem with the user assigned to run the service. Make sure you test with the same user you’re using on the production server.

Method 5

As John Saunders asks in his comment, please post more of the stack trace, including if possible the lines throwing the expception.

However, using some psychic debugging skills, I’m going to take a couple of wild stabs here that might help:

  1. IsolatedStorageException can be thrown by both GetStore and the IsolatedStorageFileStream constructor
  2. “It works fine in Windows XP” – when you run the site in the Visual Studio built in web server running under your (probably admin) credentials, but certainly as a User with a profile, and therefore an Isolated Storage folder.
  3. “But on production it throws an exception” – when it’s running under either “Network Service” or some other account that doesn’t have a profile, or Interact with Desktop type rights (not sure of the specifics – it’s mainly the lack of a profile that’s a killer).

What sort of account is the site running under in prodution? I assume it’s not a user that is able to log on to the server and interact with the file system properly?


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x