我有这样的代码:
public void zapiszDoPliku(string sciezkaDoPliku, IsolatedStorageFile katalog)
{
IsolatedStorageFileStream strumien = katalog.CreateFile(sciezkaDoPliku); // tworzenie pliku
MemoryStream ms = new MemoryStream();
StreamReader r = new StreamReader(ms);
DataContractSerializer serializer = new DataContractSerializer(typeof(kontenerUstawienia));
//--v-- HERE IS EXCEPTION THROWED
serializer.WriteObject(ms, this);
ms.Position = 0;
string daneDoZapisania = r.ReadToEnd();
byte[] bytes = Encoding.Unicode.GetBytes(daneDoZapisania);
strumien.Write(bytes, 0, bytes.Length);
ms.Close();
strumien.Close();
}
在'// - v--这里是例外情况下'被抛出异常
An exception of type 'System.Runtime.Serialization.InvalidDataContractException'
occurred in System.Runtime.Serialization.ni.dll but was not handled in user code
If there is a handler for this exception, the program may be safely continued.
代码的第二部分:
IsolatedStorageFileStream strumien; // otwarcie pliku do odczytu
try
{
strumien = katalog.OpenFile(sciezkaDoPliku, FileMode.Open);
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine("Nie odnaleziono pliku ustawien gry");
return;
}
它把我扔到了这里:
An exception of type
'System.IO.IsolatedStorage.IsolatedStorageException'
occurred in mscorlib.ni.dll but was not handled in user code
If there is a handler for this exception, the program may be safely continued.
这里发生了什么。为什么会抛出这种例外? 我在msdn上搜索并读取存储已被禁用。但我不知道如何启用它。