Page view counter
Isolated storage bug.
Last post 03-30-2008 10:56 PM by jjy2. 6 replies.
Sort Posts:
03-20-2008 6:17 PM
Isolated storage bug.

I am writing some simple settings.xml file fro saving some application state (not using ApplicationSettings) and I have the following issues:

I write out the settings int he Application_exit handler.

I then try to load them in the Application_startup handler.

 

The exit handler writes fine. The startup handler see's not files in the store the next run. However when the second run terminates I can see the previous files in the exit handler.

It appears the "isolation" level for the files changes depending on where it occurs in your application.

I moved the Load into my pages constuctory and the save into the object when it's modified and now they work correctly.

 

In other words if you write files in the exit handler you cannot access them within the scope of the application during runtime.

bpatters

Loading...
Joined on 05-16-2007
Posts 24
03-24-2008 6:14 AM
Re: Isolated storage bug.

Hello, can you post some code? Just tried this and it works. The file is opened successfully in Application.Startup event, and the content "abc" is read successfully.

private void Application_Exit(object sender, EventArgs e)

{

IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication();

IsolatedStorageFileStream stream = file.CreateFile("test.txt");

string s = "abc";byte[] b = Encoding.UTF8.GetBytes(s);

stream.Write(b, 0, b.Length);

stream.Flush();

stream.Close();

}

 

private void Application_Startup(object sender, StartupEventArgs e)

{

IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication();if (file.FileExists("test.txt"))

{

IsolatedStorageFileStream stream = file.OpenFile("test.txt", System.IO.FileMode.Open);

byte[] b = new byte[stream.Length];

stream.Read(b, 0, b.Length);

string s = Encoding.UTF8.GetString(b, 0, b.Length);

stream.Close();

}

// Load the main control

this.RootVisual = new Page();

}

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.

Yi-Lun Luo - MSFT

Loading...
Joined on 10-29-2007
Posts 2,688
03-24-2008 5:03 PM
Re: Isolated storage bug.

That is pretty much exactly what I was doing. The only difference was the filename and content I was writing. It must be environmental if that works for you.

 I'm running Windows Vista Ultimate and I have UAC enabled. Perhaps it's the UAC? I can try turning it off when I get home and see if it works.

The part that was failing for me (I stepped through it in the debugger) was the file.Exists("usersettings.xml") line of code during my LoadSettings method was always returning false. In order to debug this I added the following line to the app exit and start code just after creating the IsolatedStorageFileStream:

string[] files = file.getFileNames();

and then stepped through with the debugger. The exit code (where the file was created) would show a list with 1 element of "usersettings.xml" in it, and the startup code where I loaded it would show an empty files list at all times. I then moved my LoadSettings() and SaveSettings() methods around until it worked. Which was inside the Page constructor for Load (and the save is in the settings object when a property changes).

 

 

bpatters

Loading...
Joined on 05-16-2007
Posts 24
03-30-2008 8:55 AM
Re: Isolated storage bug.


I have the same problem.

I was examining IsolaedStorageFile's property in debugger

It seems IsolatedStorageFile.GetUserStoreForApplication() return file that is pointing different directory on StartUp and Exit

I copied below from debug window.

StartUp, IsolatedStorageFile's
m_StorePath = “…Silverlight\is\c3jsgwwy.eat\kwqicyij.jjn\s\l10oe2qfpbbupah25l1afe05gkihskbs
RootDirectory = "…Silverlight\is\c3jsgwwy.eat\kwqicyij.jjn\s\l10oe2qfpbbupah25l1afe05gkihskbs\f"

On Exit
m_StorePath = “…Silverlight\is\c3jsgwwy.eat\kwqicyij.jjn\s\ceapnxl33xmtzpg24xtnwfqgewum3eiz
RootDirectory = "… Silverlight\is\c3jsgwwy.eat\kwqicyij.jjn\s\ceapnxl33xmtzpg24xtnwfqgewum3eiz\f "

I am using VISTA Ultimate


 

jjy2

Loading...
Joined on 09-17-2007
Posts 153
03-30-2008 9:06 AM
Re: Isolated storage bug.

Oh, It wasn’t exactly StartUp when isolated stored file is first accessed.


Here is what I did.
1. OnStartUp -> Download files
2. After last OpenReadCompletedEventHandler is called, I read Isolated Storage file
3.  On Exit -> Save some data
 

Then IsolatedStorageFile.GetUserStoreForApplication() return file that is pointing different directory

 

 

jjy2

Loading...
Joined on 09-17-2007
Posts 153
03-30-2008 10:23 PM
Re: Isolated storage bug.

Thanks for reporting this issue. I've verified it's a known bug, and will probably be fixed.

For now, a workaround is to cache the isolated storage path in the Startup event, or handle the html window.onunload event instead of Silverlight's Exit event.

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.

Yi-Lun Luo - MSFT

Loading...
Joined on 10-29-2007
Posts 2,688
03-30-2008 10:56 PM
Re: Isolated storage bug.

Yi-Lun Luo - MSFT:
For now, a workaround is to cache the isolated storage path in the Startup event

Thanks!. That worked nicely.

 

jjy2

Loading...
Joined on 09-17-2007
Posts 153
Microsoft Communities