【问题标题】:Simple Protobuf-net code failing in MonoDroid with 'No serializer defined for type'MonoDroid 中的简单 Protobuf-net 代码失败,“没有为类型定义序列化程序”
【发布时间】: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


【解决方案1】:

几天前我收到了这个报告;这是一个意外的回归,因为 Mono KeyValuePair 具有与 .NET 不同的访问器,并且新的“元组”处理不同意它是合适的匹配项(基本上,在 Mono 中,它们有私有设置器,这对它不利) .

我会在这个周末修复这个问题并重新部署。诚挚的歉意。

【讨论】:

  • 嗯,它总是让你得到最微小的东西......谢谢! =)
  • @tempy 获取信息,我已经在本地修补了这个 - 只是运行测试套件等。有问题的 Mono 代码:t.co/cfuhIVBK(protobuf-net 想要“正确的”不可变元组)
  • 那些不必要的二传手看起来很无辜。
猜你喜欢
  • 1970-01-01
  • 2013-11-17
  • 1970-01-01
  • 2022-01-04
  • 2012-09-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多