我看到我可以通过设置DynamicType = true来序列化接口派生类而无需预先指定,如here所示。
但是我正在尝试序列化其值为接口列表的Dictionary,如下所示:
[ProtoMember(35, DynamicType=true)]
public Dictionary<int, List<iAnInterface>> vals;
我收到此错误:
System.InvalidOperationException:无法为System.Collections.Generic.Dictionary
2[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Collections.Generic.List
解析合适的Add方法1 [[myFuncs.iFilter,myFuncs20,Version = 1.0.5367.32298,Culture = neutral,PublicKeyToken = null] ],mscorlib,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089]] at ProtoBuf.Serializers.ListDecorator..ctor(TypeModel model,Type declaredType,Type concreteType,IProtoSerializer tail,Int32 fieldNumber,Boolean writePacked,WireType packedWireType,Boolean returnList,Boolean overwriteList,Boolean supportsNull)in c:\ Dev \ protobuf-net \ protobuf-net \ Serializers \ ListDecorator.cs:第85行 at ProtoBuf.Meta.ValueMember.BuildSerializer()in c:\ Dev \ protobuf-net \ protobuf-net \ Meta \ ValueMember.cs:348行 at ProtoBuf.Meta.ValueMember.get_Serializer()in c:\ Dev \ protobuf-net \ protobuf-net \ Meta \ ValueMember.cs:第191行 在ProtoBuf.Meta.MetaType.BuildSerializer()中的c:\ Dev \ protobuf-net \ protobuf-net \ Meta \ MetaType.cs:第465行 在ProtoBuf.Meta.MetaType.get_Serializer()中的c:\ Dev \ protobuf-net \ protobuf-net \ Meta \ MetaType.cs:第381行 at ProtoBuf.Meta.RuntimeTypeModel.Serialize(Int32 key,Object value,ProtoWriter dest)在c:\ Dev \ protobuf-net \ protobuf-net \ Meta \ RuntimeTypeModel.cs:第692行 at ProtoBuf.Meta.TypeModel.SerializeCore(ProtoWriter writer,Object value)在c:\ Dev \ protobuf-net \ protobuf-net \ Meta \ TypeModel.cs:第186行 at ProtoBuf.Meta.TypeModel.Serialize(Stream dest,Object value,SerializationContext context)在c:\ Dev \ protobuf-net \ protobuf-net \ Meta \ TypeModel.cs:第217行 at ProtoBuf.Meta.TypeModel.Serialize(Stream dest,Object value)在c:\ Dev \ protobuf-net \ protobuf-net \ Meta \ TypeModel.cs:第201行 at ProtoBuf.Serializer.Serialize [T](Stream destination,T instance)在c:\ Dev \ protobuf-net \ protobuf-net \ Serializer.cs:第87行
我正在尝试做什么?
编辑:如果我尝试做一个List(即没有围绕它的字典),它就可以了。