【发布时间】:2011-10-07 16:12:47
【问题描述】:
以下代码在 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,版本=2.0.5.0,文化=中性,PublicKeyToken=7cec85d7bea7798e]] 在 ProtoBuf.Meta.ValueMember.BuildSerializer () [0x00000] in :0 在 ProtoBuf.Meta.ValueMember.get_Serializer () [0x00000] in :0 在 ProtoBuf.Meta.MetaType.BuildSerializer () [0x00000] in :0 在 ProtoBuf.Meta.MetaType.get_Serializer () [0x00000] in :0 在 ProtoBuf.Meta.RuntimeTypeModel.Serialize(Int32 键,System.Object 值,ProtoBuf.ProtoWriter dest)[0x00000] in :0 在 ProtoBuf.Meta.TypeModel.SerializeCore(ProtoBuf.ProtoWriter 编写器,System.Object 值)[0x00000] in :0 在 ProtoBuf.Meta.TypeModel.Serialize (System.IO.Stream dest, System.Object 值, ProtoBuf.SerializationContext 上下文) [0x00000] in :0 在 ProtoBuf.Meta.TypeModel.Serialize (System.IO.Stream dest, System.Object 值) [0x00000] in :0 在 ProtoBuf.Serializer.Serialize[SSDTO](System.IO.Stream 目标,ABC.SystemModel.SSDTO 实例)[0x00000] in :0 在 C:\CODE\SettingStore.cs:145 中的 ABC.SystemModel.SettingStore.Serialize (System.IO.Stream Target) [0x00002]
我在源主干中的 monodroid 项目中为 Monodroid 编译了 protobuf-net 发布版本,这是我 3-4 天前抓取的。
【问题讨论】:
-
r447 现在可以下载了;请让我知道这是否能解决这个问题
-
是的,这解决了我的问题,再次感谢!
标签: protocol-buffers protobuf-net xamarin.android