Unexpected sub-type: UnnamedGameServer.TrapInstance
在 protobuf-net 中序列化时出现异常。
这是代码:
class test
{
void testMethod(PacketNewTrapResponse packet)
{
using (var stream = new MemoryStream())
{
Serializer.SerializeWithLengthPrefix<PacketNewTrapResponse>(stream, (PacketNewTrapResponse)packet, PrefixStyle.Base128);
}
}
}
[ProtoContract]
public class MapTrap
{
[ProtoMember(1)]
public IntegerVector2 Position;
[ProtoMember(2)]
public int TrapServerID;
[ProtoMember(3)]
public int LocationID;
}
[ProtoContract, ProtoInclude(1, typeof(MapTrap))]
class TrapInstance : MapTrap
{
public TrapInstance(TrapProperties trap, SessionCharacter session, int serverTrapId, int locationId, IntegerVector2 position)
{
TrapServerID = serverTrapId;
Trap = trap;
Position = position;
LocationID = locationId;
OwnerOfTrap = session;
LocationID = locationId;
Position = position;
}
public SessionCharacter OwnerOfTrap { get; set; }
public TrapProperties Trap { get; set; }
}