Serialization in Mono

  • Thread starter Thread starter Nikola Skoric
  • Start date Start date
N

Nikola Skoric

I ran in Mono a program developed on .NET Framework 2.0 and it ran OK
until I tried to desirialize a object. There the program died abruptly
dumping this:

System.ArgumentOutOfRangeException: Value -8590321990885400808 is
outside the valid range [0,3155378975999999999].
Parameter name: ticks
at System.DateTime..ctor (Int64 ticks) [0x00000]
at
System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadPrimitiv
eTypeValue (System.IO.BinaryReader reader, System.Type type) [0x00000]
at
System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadValue
(System.IO.BinaryReader reader, System.Object parentObject, Int64
parentObjectId, System.Runtime.Serialization.SerializationInfo info,
System.Type valueType, System.String fieldName,
System.Reflection.MemberInfo memberInfo, System.Int32[] indices)
[0x00000]
at
System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObjectCo
ntent (System.IO.BinaryReader reader,
System.Runtime.Serialization.Formatters.Binary.TypeMetadata metadata,
Int64 objectId, System.Object& objectInstance,
System.Runtime.Serialization.SerializationInfo& info) [0x00000]
at
System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObjectIn
stance (System.IO.BinaryReader reader, Boolean isRuntimeObject, Boolean
hasTypeInfo, System.Int64& objectId, System.Object& value,
System.Runtime.Serialization.SerializationInfo& info) [0x00000]
at
System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObject
(BinaryElement element, System.IO.BinaryReader reader, System.Int64&
objectId, System.Object& value,
System.Runtime.Serialization.SerializationInfo& info) [0x00000]
at
System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadNextObje
ct (System.IO.BinaryReader reader) [0x00000]
at
System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObjectGr
aph (System.IO.BinaryReader reader, Boolean readHeaders, System.Object&
result, System.Runtime.Remoting.Messaging.Header[]& headers) [0x00000]
at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.NoCheckDe
serialize (System.IO.Stream serializationStream,
System.Runtime.Remoting.Messaging.HeaderHandler handler) [0x00000]
at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deseriali
ze (System.IO.Stream serializationStream) [0x00000]
at LanguageSystem.WordDisplay.openFileDialog1_FileOk (System.Object
sender, System.ComponentModel.CancelEventArgs e) [0x00000]
at (wrapper delegate-invoke)
System.MulticastDelegate:invoke_void_object_CancelEventArgs
(object,System.ComponentModel.CancelEventArgs)
at System.Windows.Forms.FileDialog.OnFileOk
(System.ComponentModel.CancelEventArgs e) [0x00000]
at System.Windows.Forms.FileDialog.OnClickOpenSaveButton
(System.Object sender, System.EventArgs e) [0x00000]
at System.Windows.Forms.FileDialog.OnForceDialogEndFileView
(System.Object sender, System.EventArgs e) [0x00000]
at (wrapper delegate-invoke)
System.MulticastDelegate:invoke_void_object_EventArgs
(object,System.EventArgs)
at System.Windows.Forms.MWFFileView.OnDoubleClick (System.EventArgs e)
[0x00000]
at System.Windows.Forms.ListView+ItemControl.ItemsMouseDown
(System.Object sender, System.Windows.Forms.MouseEventArgs me) [0x00000]
at (wrapper delegate-invoke)
System.MulticastDelegate:invoke_void_object_MouseEventArgs
(object,System.Windows.Forms.MouseEventArgs)
at System.Windows.Forms.Control.OnMouseDown
(System.Windows.Forms.MouseEventArgs e) [0x00000]
at System.Windows.Forms.Control.WndProc (System.Windows.Forms.Message&
m) [0x00000]
at System.Windows.Forms.ListView+ItemControl.WndProc
(System.Windows.Forms.Message& m) [0x00000]
at System.Windows.Forms.Control+ControlNativeWindow.WndProc
(System.Windows.Forms.Message& m) [0x00000]
at System.Windows.Forms.NativeWindow.WndProc (IntPtr hWnd, Msg msg,
IntPtr wParam, IntPtr lParam) [0x00000]

I've been trying to figure out what went wrong, but I can't see it. Any
ideas?
 
Look at the first error in the hierarchy - all the others just tell
you that one of their subroutines failed.
System.ArgumentOutOfRangeException: Value -8590321990885400808 is
outside the valid range [0,3155378975999999999].
Parameter name: ticks
at System.DateTime..ctor (Int64 ticks) [0x00000]

It looks llike you have an invalid number of ticks where the app is
trying to reconstruct a DateTime using a constructor with a single
Int64 parameter of the number of ticks.

Check for file corruption, or for an improperly constructed file.

rossum
 
I ran in Mono a program developed on .NET Framework 2.0 and it ran OK
until I tried to desirialize a object. There the program died abruptly
dumping this:

System.ArgumentOutOfRangeException: Value -8590321990885400808 is
outside the valid range [0,3155378975999999999].
Parameter name: ticks
at System.DateTime..ctor (Int64 ticks) [0x00000]
at
System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadPrimitiv
eTypeValue (System.IO.BinaryReader reader, System.Type type) [0x00000]
[...]

Well, at first glance it appears to be a signed/unsigned mismatch. But, I
suppose it's also possible that the exception output is incorrectly
formatting the input value and that it's simply a genuine "your number is
too big" exception.

What I would do is take the maximum value described in the range
(3155378975999999999) and set a DateTime object to that to see what actual
date and time that corresponds to. Then look at the input data and see if
you can figure out why it's resulting in a tick count
(-8590321990885400808) that's outside the allowed range.

Somewhere you're reading a date/time value that the Mono version of
DateTime doesn't like. This may be because the Mono DateTime doesn't
handle the same range as the .NET DateTime, it might be because of some
sort of byte-swapping issue (depending on what you're running Mono on), it
might be because of some data structure packing or alignment problem, or
something else entirely. But the first step would be to figure out if the
numbers you're seeing in the exception make any sense (and at first
glance, having a negative number where only positive numbers are allowed
doesn't make sense :) ).

Pete
 
What I would do is take the maximum value described in the range
(3155378975999999999) and set a DateTime object to that to see what actual
date and time that corresponds to. Then look at the input data and see if
you can figure out why it's resulting in a tick count
(-8590321990885400808) that's outside the allowed range.

Thanks, Pete, you have been very helpful. It turns out that
d = DateTime.FromBinary(3155378975999999999);
Console.WriteLine(d);
returns 31.12.9999 23:59:59. And
d = DateTime.Now;
Console.WriteLine(d.ToBinary());
returns
-8590223521125949343

Now, it seems like Mono and .NET Framework have some big compatibility
issues here...
 
Thanks, Pete, you have been very helpful. It turns out that
d = DateTime.FromBinary(3155378975999999999);
Console.WriteLine(d);
returns 31.12.9999 23:59:59. And
d = DateTime.Now;
Console.WriteLine(d.ToBinary());
returns
-8590223521125949343

Now, it seems like Mono and .NET Framework have some big compatibility
issues here...

You original error messsage talked about "ticks" - the Mono
constructor seemed to need Ticks as input. What does d.Ticks return?
Is that number within the expected range?

The documentation for DateTime mentions both ToBinary() and
FromBinary() to serialize and deserialize a DateTime object. Are you
trying to serialize with ToBinary() and deserialize with a
constructor?

Try deserializing with FromBinary(), that might work better.

rossum
 
[...]
The documentation for DateTime mentions both ToBinary() and
FromBinary() to serialize and deserialize a DateTime object. Are you
trying to serialize with ToBinary() and deserialize with a
constructor?

Try deserializing with FromBinary(), that might work better.

Or conversely, serializing with the Ticks property. Though, since you're
serializing to a binary data storage, I'd say the previous suggestion is
probably better (use FromBinary()). Just offering alternatives. :)

Either way, that may well be the problem.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top