In my application, I'm serializing messages to send over the wire using protobuf-net. Each message has a list of key-value pairs for header information.
However, I'm running into an exception and I've been able to reproduce it with a very simplified example:
[TestFixture]
public class SerializationTests
{
[ProtoContract]
public class MyType
{
[ProtoMember(1, DynamicType = true)]
public object Property { get; set; }
}
[Test]
public void SerializationTest()
{
var myType = new MyType {Property = DateTime.UtcNow.ToBinary()};
Action action = () => myType.Serialize();
action.ShouldNotThrow();
}
}
public static byte[] Serialize<T>(this T itemToSerialize)
{
using (MemoryStream ms = new MemoryStream())
{
ProtoBuf.Serializer.Serialize(ms, itemToSerialize);
byte[] objectArray = ms.ToArray();
return objectArray;
}
}
This test currently fails with the exception: System.InvalidOperationException: "Dynamic type is not a contract-type: Int64".
The property is of type object so I can put various data in there - since this is header information. I'm trying to avoid having multiple header lists where each one is strongly typed.
If I change Property to be of type long, then the test works. If I remove the DynamicType=true, then I get an exception indicating that no serializer exists for type object.
Since the test works when I change the type of Property, that seems to imply that DynamicType and long's don't work together.
I'm currently using r640 (I believe that's the latest on NuGet).