[Mono-bugs] [Bug 552891] Mono can't deserialize Nullable objects created by .NET (BinaryFormatter)

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Mon Nov 9 18:07:36 EST 2009


User jorge.matias at fractaliasoftware.com added comment

--- Comment #3 from Jorge Matias <jorge.matias at fractaliasoftware.com>  2009-11-09 16:07:35 MST ---
Created an attachment (id=326371)
 --> (http://bugzilla.novell.com/attachment.cgi?id=326371)
Quick & dirty fix that deserializes MS .NET Nullable objects

The following patch is able to deserialize Nullable objects created by MS .NET,
but should be considered a _hack_ since I'm far of being an expert on the

It seems MS .NET runtime does some tricky things (sort of optimization?) with
Nullable objects when they are not null, which doesn't allow Mono to
deserialize them.

For example, if a Nullable<int> is set to null, the serialized binary contains
the following string:

System.Nullable`1[[System.Int32, mscorlib, Version=, Culture=neutral,

But if it's not null, the serialized binary contains just the System.Int32,
with the only difference that is detected by the Mono BinaryFormatter as a
RuntimeType instead a PrimitiveType. This _may_ be related with autoboxing;
after the change ReadValue detects the element as a BoxedPrimitiveTypeValue and
procedes to deserialize the object correctly.


Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.

More information about the mono-bugs mailing list