以下代码在WP7和Windows上按原样运行,我现在试图让它在MonoDroid上运行:
[ProtoContract]
public class SSDTO {
[ProtoMember(1)]
public Dictionary<string, string> Strings = new Dictionary<string, string>(50);
[ProtoMember(2)]
public Dictionary<string, int> Ints = new Dictionary<string, int>(50);
[ProtoMember(3)]
public Dictionary<string, byte[]> Bytes = new Dictionary<string, byte[]>(10);
}
public class SettingStore {
public event EventHandler ContentsChanged;
private Dictionary<string, string> _StringVals;
private Dictionary<string, int> _IntVals;
private Dictionary<string, byte[]> _ByteVals;
public SettingStore() {
_StringVals = new Dictionary<string, string>(50);
_IntVals = new Dictionary<string, int>(50);
_ByteVals = new Dictionary<string, byte[]>(10);
}
private SettingStore(SSDTO source) {
_StringVals = source.Strings;
_IntVals = source.Ints;
_ByteVals = source.Bytes;
}
//删除了访问者
public static SettingStore DeSerialize(Stream data) {
return new SettingStore(Serializer.Deserialize<SSDTO>(data));
}
public void Serialize(Stream Target) {
Serializer.Serialize<SSDTO>(Target, toDTO());
}
private SSDTO toDTO() {
return new SSDTO { Ints = this._IntVals, Strings = this._StringVals, Bytes = this._ByteVals };
}
}
我得到的例外:
System.InvalidOperationException:没有为类型定义的序列化程序:System.Collections.Generic.KeyValuePair`2 [[System.String,mscorlib,Version = 2.0.5.0,Culture = neutral,PublicKeyToken = 7cec85d7bea7798e],[System.String, mscorlib,Version = 2.0.5.0,Culture = neutral,PublicKeyToken = 7cec85d7bea7798e]] 在ProtoBuf.Meta.ValueMember.BuildSerializer()[0x00000] in:0 在ProtoBuf.Meta.ValueMember.get_Serializer()[0x00000]中:0 在ProtoBuf.Meta.MetaType.BuildSerializer()[0x00000]中:0 在ProtoBuf.Meta.MetaType.get_Serializer()[0x00000]中:0 在ProtoBuf.Meta.RuntimeTypeModel.Serialize(Int32 key,System.Object value,ProtoBuf.ProtoWriter dest)[0x00000] in:0 在ProtoBuf.Meta.TypeModel.SerializeCore(ProtoBuf.ProtoWriter writer,System.Object value)[0x00000] in:0 在ProtoBuf.Meta.TypeModel.Serialize(System.IO.Stream dest,System.Object value,ProtoBuf.SerializationContext context)[0x00000] in:0 在ProtoBuf.Meta.TypeModel.Serialize(System.IO.Stream dest,System.Object value)[0x00000] in:0 在ProtoBuf.Serializer.Serialize [SSDTO](System.IO.Stream目的地,ABC.SystemModel.SSDTO实例)[0x00000] in:0 在C:\ CODE \ SettingStore.cs中的ABC.SystemModel.SettingStore.Serialize(System.IO.Stream目标)[0x00002]:145
我从源干线的monodroid项目中发布了monodroid的protobuf-net,这是我在3-4天前抓获的。
答案 0 :(得分:2)
我将在本周末修复 并重新部署。真诚的道歉。