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.
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.
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.
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).
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
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.
bpatters
Member
50 Points
24 Posts
Isolated storage bug.
Mar 20, 2008 10:17 PM | LINK
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 Luo -...
All-Star
25149 Points
2759 Posts
Microsoft
Re: Isolated storage bug.
Mar 24, 2008 10:14 AM | LINK
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();}
bpatters
Member
50 Points
24 Posts
Re: Isolated storage bug.
Mar 24, 2008 09:03 PM | LINK
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
Member
354 Points
155 Posts
Re: Isolated storage bug.
Mar 30, 2008 12:55 PM | LINK
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
Member
354 Points
155 Posts
Re: Isolated storage bug.
Mar 30, 2008 01:06 PM | LINK
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
Yi-Lun Luo -...
All-Star
25149 Points
2759 Posts
Microsoft
Re: Isolated storage bug.
Mar 31, 2008 02:23 AM | LINK
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.
jjy2
Member
354 Points
155 Posts
Re: Isolated storage bug.
Mar 31, 2008 02:56 AM | LINK
Thanks!. That worked nicely.