0
這是 How to set [DataMember] on all class membersDataContract序列錯誤
延續所以我必須序列與字典和其他成員的類。
我已經chonse DataContext的系列化富硒
public SimpleDataGridSample()
{
if (false)
{
MyClass theclass = new MyClass();
var serializer = new DataContractSerializer(typeof(MyClass));
using (Stream fileStream = File.Open("aaa.bin", FileMode.Create))
{
XmlDictionaryWriter binaryDictionaryWriter = XmlDictionaryWriter.CreateBinaryWriter(fileStream);
serializer.WriteObject(binaryDictionaryWriter, theclass);
binaryDictionaryWriter.Flush();
}
}
else
{
MyClass theclass;
var serializer = new DataContractSerializer(typeof(MyClass));
using (Stream fileStream = File.Open("aaa.bin", FileMode.Open))
{
XmlDictionaryReaderQuotas xq = new XmlDictionaryReaderQuotas();
XmlDictionaryReader binaryDictionarReader = XmlDictionaryReader.CreateBinaryReader(fileStream, xq);
theclass = (MyClass)serializer.ReadObject(binaryDictionarReader);
}
}
}
}
和工作。
但這只是一個測試程序。 應用於我的類,它是比較複雜的。當我得到這個錯誤:
{"Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index"}
不明白什麼指數在談論。
主要類由多個成員(也是字典和可觀察列表)和其他子類組成。 每一個類被標記[DataContract(IsReference = true)]
一個成員被標記[DataContext]
感謝名單,這是不可能的其他用戶aswer