Serisalizing long in BSON

Nov 8, 2010 at 10:20 AM

Hi,

You have produced a great lib! But now I have a problem.

When I try to serialize an object containg a long I got an (overflow) exception.

Here is the stack trace of the excetion:

TestCase 'Agfa.Healthcare.Common.Cx.Licensing.InterOpt.Tests.TestMessageDeserializer.Serialize'
failed: System.OverflowException : Value was either too large or too small for an Int32.
    at System.Convert.ToInt32(Int64 value)
    at System.Int64.System.IConvertible.ToInt32(IFormatProvider provider)
    at System.Convert.ToInt32(Object value, IFormatProvider provider)
    d:\Development\Source\Json\trunk\Src\Newtonsoft.Json\Bson\BsonWriter.cs(98,0): at Newtonsoft.Json.Bson.BsonWriter.WriteToken(JToken t)
    d:\Development\Source\Json\trunk\Src\Newtonsoft.Json\Bson\BsonWriter.cs(77,0): at Newtonsoft.Json.Bson.BsonWriter.WriteToken(JToken t)
    d:\Development\Source\Json\trunk\Src\Newtonsoft.Json\Bson\BsonWriter.cs(77,0): at Newtonsoft.Json.Bson.BsonWriter.WriteToken(JToken t)
    d:\Development\Source\Json\trunk\Src\Newtonsoft.Json\Bson\BsonWriter.cs(272,0): at Newtonsoft.Json.Bson.BsonWriter.WriteEnd(JsonToken token)
    d:\Development\Source\Json\trunk\Src\Newtonsoft.Json\JsonWriter.cs(513,0): at Newtonsoft.Json.JsonWriter.AutoCompleteClose(JsonToken tokenBeingClosed)
    d:\Development\Source\Json\trunk\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalWriter.cs(310,0): at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract)
    d:\Development\Source\Json\trunk\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalWriter.cs(109,0): at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonConverter memberConverter, JsonContract contract)
    d:\Development\Source\Json\trunk\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalWriter.cs(61,0): at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value)
    d:\Development\Source\Json\trunk\Src\Newtonsoft.Json\JsonSerializer.cs(432,0): at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value)
    d:\Development\Source\Json\trunk\Src\Newtonsoft.Json\JsonSerializer.cs(424,0): at Newtonsoft.Json.JsonSerializer.Serialize(JsonWriter jsonWriter, Object value)
    D:\Profiles\amntu\Desktop\BSON\LicSerialization\MessageSerializer.cs(18,0): at Agfa.Healthcare.Common.Cx.Licensing.InterOpt.MessageSerializer.Serialize(Stream stream, Message msg)
    D:\Profiles\amntu\Desktop\BSON\TestLicSerialization\TestMessageDeserializer.cs(35,0): at Agfa.Healthcare.Common.Cx.Licensing.InterOpt.Tests.TestMessageDeserializer.Serialize()

Is there away to serialize a long to BSON?


Thanks!!

Coordinator
Nov 10, 2010 at 7:09 AM

Are you using the latest version? An example of the class you are serializing would be helpful.