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; }
}