Reputation: 2085
I received a stack trace report which says there is an IsolatedStorageException.
"Frame Image Function Offset
0 coredll.dll xxx_RaiseException
1 mscoree3_7.dll
2 mscoree3_7.dll
3 mscoree3_7.dll
4 TransitionStub
5 System.IO.IsolatedStorage.IsolatedStorageSettings.Save
6 System.IO.IsolatedStorage.IsolatedStorageSettings.Clear
7 AppName.CycleManager.WriteToIsolatedStorage
8 AppName.SettingsPage.OnNavigatedFrom
9 Microsoft.Phone.Controls.PhoneApplicationPage.InternalOnNavigatedFrom
10 System.Windows.Navigation.NavigationService.RaiseNavigated
11 System.Windows.Navigation.NavigationService.CompleteNavigation
12 System.Windows.Navigation.NavigationService.ContentLoader_BeginLoad_Callback
13 System.Windows.Navigation.PageResourceContentLoader.BeginLoad_OnUIThread
14 ._c_DisplayClass4._BeginLoad_b__0
15 mscoree3_7.dll
16 mscoree3_7.dll
17 mscoree3_7.dll
18 System.Reflection.RuntimeMethodInfo.InternalInvoke
19 System.Reflection.RuntimeMethodInfo.InternalInvoke "
So I presume it the exception is raised by the WriteToIsolatedStorage().
public void WriteToIsolatedStorage()
{
IsolatedStorageSettings dataStorage = IsolatedStorageSettings.ApplicationSettings;
dataStorage.Clear();
dataStorage.Add("firstLaunchDate", App.LaunchedDateTime);
dataStorage.Add("weekStart", m_bWeekStart);
dataStorage.Add("iHistCount", m_iHistCount);
// All the variables i need to store
dataStorage.Add("noteCount", m_noteCount);
WriteNotesToFile();
dataStorage.Add("weightCount", m_iWeightCount);
WriteWeightToFile();
dataStorage.Add("tempCount", m_iTempCount);
WriteTempToFile();
dataStorage.Save();
}
UPDATE:
public void WriteNotesToFile()
{
if (m_noteCount > 0)
{
try
{
using (IsolatedStorageFile storagefile = IsolatedStorageFile.GetUserStoreForApplication())
{
if (storagefile.FileExists("NotesFile"))
{
using (IsolatedStorageFileStream fileStream = storagefile.OpenFile("NotesFile", FileMode.Open, FileAccess.ReadWrite))
{
StreamWriter writer = new StreamWriter(fileStream);
for (int i = 0; i < m_noteCount; i++)
{
//writer.Write(m_arrNoteDate[i].ToShortDateString());
writer.Write(m_arrNoteDate[i].ToString("d", CultureInfo.InvariantCulture));
writer.Write(" ");
writer.Write(m_arrNoteString[i]);
writer.WriteLine("~`");
}
writer.Close();
}
}
else
{
storagefile.CreateFile("NotesFile.txt");
using (IsolatedStorageFileStream fileStream = storagefile.OpenFile("NotesFile", FileMode.Create, FileAccess.ReadWrite))
{
StreamWriter writer = new StreamWriter(fileStream);
for (int i = 0; i < m_noteCount; i++)
{
//writer.Write(m_arrNoteDate[i].ToShortDateString());
writer.Write(m_arrNoteDate[i].ToString("d", CultureInfo.InvariantCulture));
writer.Write(" ");
writer.Write(m_arrNoteString[i]);
writer.WriteLine("~`");
}
writer.Close();
}
}
}
}
catch { }
}
}
Could anyone tell me in which condition the Exception is thrown. I read somewhere that when there is not enough of space, such exception will be thrown.
Lastly, I have 4 isolated storage files to which i write values.Does the following method remove all 4 of them?
IsolatedStorageFile storagefile = IsolatedStorageFile.GetUserStoreForApplication();
storagefile.Remove();
I would be really grateful if someone could clarify these.
Thank you,
Upvotes: 0
Views: 341
Reputation: 65564
The call to Save
would fail if there wasn't enough space.
As we can't see what the WriteXxxxToFile()
methods are doing, they could be doing something which could cause this issue.
It could also be tied to issues where you have multiple threads trying to access the settings or the app closing or tombstoning but your save method taking too long.
Your best bet for identifying the true cause would be to add some handling to support the scenario where a call to WriteToIsolatedStorage()
raises such an exception and then log and report it as is appropriate to your app/needs.
Regarding Remove
, as per MSDN
"This method irrevocably removes the entire isolated storage for the current users's application and all its directories and files."
Upvotes: 2