Silverlight で Windows Phone 7 アプリを作成しています。で困っていIsolatedStorage
ます。
IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();
if (!storage.FileExists(STORIES_FILE))
{
storage.CreateFile(STORIES_FILE);
}
string contents;
// fails here
using (IsolatedStorageFileStream stream = storage.OpenFile(STORIES_FILE, FileMode.Open))
{
using (StreamReader reader = new StreamReader(stream))
{
contents = reader.ReadToEnd();
}
}
例外は次のとおりです。
"Operation not permitted on IsolatedStorageFileStream."
System.Exception {System.IO.IsolatedStorage.IsolatedStorageException}
ここで何が間違っているのでしょうか?MSDN によると、この例外は、分離ストレージが削除または無効化されたときにスローされるとのことです。それは起こったでしょうか?エミュレータでこの問題が発生しています。
更新:これは、エミュレーターでアプリを初めて実行したときにのみ発生するようです。アプリがクラッシュした後、エミュレーターで再度実行しましたが、この問題は発生しません。
更新 2 :FileMode.OpenOrCreate
の代わりに使用FileMode.Open
すると、問題が解決したようです。