1
プロパティのみが格納されたオブジェクトをシリアル化しています。 それは親の継承を持っていますが、シリアル化された属性が数値と異なるインデックスであることを確認しました。ProtoBuf-Net:タイプ用にシリアライザが定義されていません:System.Object
[ProtoContract]
[ProtoInclude(597, typeof(DesiredProto))]
[ProtoInclude(598, typeof(RandomClass1Proto))]
[ProtoInclude(599, typeof(RandomClass2Proto))]
[ProtoInclude(600, typeof(RandomClass3Proto))]
public class BaseProto
{
protected string mName = "";
protected string mOwner = "";
protected VObjectType mVType; //this is an enumeration!
public BaseProto(){}
[ProtoMember(1)]
public String Name
{
get { return mName; }
set { mName = value;}
}
[ProtoMember(2)]
public String Owner
{
get { return mOwner; }
set { mOwner = value;}
}
[ProtoMember(3)]
public VObjectType VType
{
get { return mVType; }
set { mVType = value;}
}
}
、その後DesiredProto:
[ProtoContract]
public class DesiredProto : BaseProto
{
protected DestinationType mDestType;
protected string mAddress = "";
public DesiredProto()
{
}
[ProtoMember(1)]
public DestinationType DestType //this is an enumeration
{
get { return mDestType; }
set { mDestType = value;}
}
[ProtoMember(2)]
public String Address
{
get { return mAddress; }
set { mAddress = value;}
}
}
は今本当に奇妙な部分は、シリアライズは一見完全に機能していることです。この「DesiredProto」をシリアライズして逆シリアル化すると、エラーが無視されます。 最後に、これはこれらのクラスの完全なコードスニペットではなく、はるかに長いですが、うまくいけばエラーが何とかこの中に含まれています。
'DestinationType'とは何ですか? –
情報のためのマイナーなことですが、C#の最新バージョンを使用している場合は、自動的に実装されたプロパティを使用することができます。 '[ProtoMember(2)] public string Address {get; set;}' - コンパイラは基本的にあなたが行ったのと全く同じですが(誤っている)フィールドなど) –
DestinationTypeは列挙型です! – jStaff