속성을 가진 집계 유형을 참조 인 추상 기본 유형으로 역 직렬화 할 수 있습니까? Aggregate.Base?를 참조하십시오. 그렇지 않은 경우 가장 좋은 해결 방법은 무엇입니까? 지점에서추상 기본 참조 속성을 deserialize
[ProtoContract]
[ProtoInclude(1, typeof(Derived))]
public abstract class Base { }
[ProtoContract]
public class Derived : Base
{
[ProtoMember(1)]
public int SomeProperty { get; set; }
}
[ProtoContract]
public class Aggregate
{
[ProtoMember(1, AsReference = true)]
public Base Base { get; set; }
}
[TestClass]
public class UnitTest
{
[TestMethod]
public void TestMethod1()
{
var value = new Aggregate { Base = new Derived() };
using (var stream = new MemoryStream())
{
Serializer.Serialize(stream, value);
stream.Position = 0;
// Raises an exception
// Unable to create type Sage.Estimating.Data.Base: Cannot create an abstract class.
Serializer.Deserialize<Aggregate>(stream);
}
}
}
호출 스택은 예외가 발생!
protobuf-net.dll ProtoBuf.BclHelpers.ReadNetObject (개체 값 ProtoBuf.ProtoReader 소스 INT 키 System.Type 형식 , ProtoBuf.BclHelpers.NetObjectOptions 옵션) 줄 428 + 0xda 바이트 C# protobuf-net.dll! ProtoBuf.Serializers.NetObjectSerializer.Read (개체 값, ProtoBuf.ProtoReader 원본) 줄 45 + 0x9f 바이트 C# protobuf-net.dll! ProtoBuf.Serializers.TagDecorator.Read (개체 값, ProtoBuf.ProtoReader 원본) 줄 66 + 0x18 바이트 C# protobuf-net.dl l! ProtoBuf.Serializers.PropertyDecorator.Read (객체 값, ProtoBuf.ProtoReader 소스) Line 74 + 0x18 bytes C# protobuf-net.dll! ProtoBuf.Serializers.TypeSerializer.Read (객체 값, ProtoBuf.ProtoReader 소스) 행 205 + 0xf 바이트 C# protobuf-net.dll! ProtoBuf.Meta.RuntimeTypeModel.Deserialize (int 키, 개체 값, ProtoBuf.ProtoReader 원본) 줄 562 + 0xf 바이트 C# protobuf-net.dll! ProtoBuf.Meta.TypeModel.DeserializeCore ProtoBuf.ProtoReader 판독기, System.Type 형식, 개체 값, bool noAutoCreate) 줄 634 + 0x14 바이트 C# protobuf-net.dll! ProtoBuf.Meta.TypeModel.Deserialize (System.IO.Stream 원본, 개체 값, System.Type 형식, ProtoBuf.SerializationContext 컨텍스트) 줄 555 + 0x14 바이트 C# protobuf-net.dll! ProtoBuf.Meta.TypeModel.Deserialize (System.IO.Stream 원본, 개체 값, System.Type 형식) 줄 534 + 0x13 C 번호를 protobuf - net.dll 바이트 ProtoBuf.Serializer.Deserialize (System.IO.Stream 소스) 라인 78 + 0x5a 바이트 C#
지금은 PC가 아니지만 1 라이너보다 더 보입니다. –
Hmmm; 이것은 지연 추적과 관련하여 흥미롭고 사소한 문제입니다. 아마도 고칠 수는 있지만, 좋은 것입니다. p 테스트 활동을 재 검증으로 확인할 수 있으므로이 최대한 빨리 조사/수정합니다. –