我不會做一些序列化與protobuf網並獲得如下因素錯誤此代碼段:protobuf網dynamictype陣列
錯誤:
Dynamic type is not a contract-type: TestType[]
的片段:
using System.IO;
namespace QuickStart
{
class Program
{
static void Main()
{
//FileAccess.ShowFileAccess();
//Sockets.ShowSockets();
var dto = new DataTransferType
{
ProtoDynamicProperty = new TestType[]
{
new TestType {UselessProperty="AAA"},
new TestType{UselessProperty="BBB"},
new TestType{UselessProperty="CCC"}
}
};
using (MemoryStream testStream = new MemoryStream())
{
ProtoBuf.Serializer.SerializeWithLengthPrefix(testStream, dto, ProtoBuf.PrefixStyle.Base128);
}
}
}
[ProtoBuf.ProtoContract]
struct TestType
{
[ProtoBuf.ProtoMember(1)]
public string UselessProperty { get; set; }
}
[ProtoBuf.ProtoContract]
class DataTransferType
{
[ProtoBuf.ProtoMember(1, DynamicType = true)]
public object ProtoDynamicProperty { get; set; }
}
}
任何想法爲什麼發生這種情況?我真的使用2.0.0.651構建
剛走回答[這個問題] (https://stackoverflow.com/questions/39208449/protobuf-net-how-to-serialize-complex-collection/39214319#39214319)我意識到我也知道這個老問題的答案,所以我繼續回答它,儘管它的年齡。 – dbc