Skip to main content
Home Forums Silverlight Programming Report a Silverlight Bug Isolated storage bug.
6 replies. Latest Post by jjy2 on March 30, 2008.
(0)
bpatters
Member
50 points
24 Posts
03-20-2008 6:17 PM |
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.
Yi-Lun L...
All-Star
25052 points
2,747 Posts
03-24-2008 6:14 AM |
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.
{
stream.Write(b, 0, b.Length);
stream.Flush();
stream.Close();
}
stream.Read(b, 0, b.Length);
03-24-2008 5:03 PM |
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).
jjy2
354 points
155 Posts
03-30-2008 8:55 AM |
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
03-30-2008 9:06 AM |
Oh, It wasn’t exactly StartUp when isolated stored file is first accessed.
Here is what I did. 1. OnStartUp -> Download files2. 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
03-30-2008 10:23 PM |
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.
03-30-2008 10:56 PM |
Yi-Lun Luo - MSFT:For now, a workaround is to cache the isolated storage path in the Startup event
Thanks!. That worked nicely.