CMertens / protobuf-net

Automatically exported from code.google.com/p/protobuf-net
Other
0 stars 0 forks source link

Serializing dynamic values doesn't seem to work in release 580 #319

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Here is the code to reproduce it:

[ProtoContract]
class TestClass
{
  [ProtoMember(1, DynamicType = true)]
  public object Property1 { get; set; }
}

[Test]
public void TestDecimal()
{
  TestClass testClass = new TestClass {Property1 = 1d};
  using (var file = File.Create("test.txt"))
  {
    Serializer.Serialize(file, testClass);
  }

}

The error is:

System.InvalidOperationException : Dynamic type is not a contract-type: Double
 at ProtoBuf.BclHelpers.WriteNetObject(Object value, ProtoWriter dest, Int32 key, NetObjectOptions options) in c:\Dev\protobuf-net\protobuf-net\BclHelpers.cs: line 515
 at proto_1(Object, ProtoWriter)
 at ProtoBuf.Meta.TypeModel.SerializeCore(ProtoWriter writer, Object value) in c:\Dev\protobuf-net\protobuf-net\Meta\TypeModel.cs: line 186
 at ProtoBuf.Meta.TypeModel.Serialize(Stream dest, Object value, SerializationContext context) in c:\Dev\protobuf-net\protobuf-net\Meta\TypeModel.cs: line 218
 at Teck.PerformanceManagement.Test.ServiceInterfaces.Services.CalculationEngine.TestSerializationSpeed.TestDecimal() in TestSerializationSpeed.cs: line 71

Original issue reported on code.google.com by costa.ba...@gmail.com on 12 Sep 2012 at 7:10

GoogleCodeExporter commented 9 years ago
I'm having the same problem... is there some known workaround?

Original comment by albert...@gmail.com on 11 Jun 2013 at 8:09

GoogleCodeExporter commented 9 years ago
Hi.

I'm having the same problem on the release 640.
Double is not the only type which is "not a contract-type".
There is the same issue with DateTime or Integer.

Original comment by nicolas1...@gmail.com on 25 Jun 2013 at 12:35