Bug 12441 - DataContractSerializer throws exception when using DataContracts, DataMembers, and multiple Nullable types
Summary: DataContractSerializer throws exception when using DataContracts, DataMembers...
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: WCF assemblies (show other bugs)
Version: master
Hardware: PC Windows
: Normal normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-05-28 19:03 UTC by Sung K
Modified: 2016-11-11 09:40 UTC (History)
5 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
An example Activity that will attempt to serialize and deserialize a custom object (2.74 KB, text/plain)
2013-05-28 19:04 UTC, Sung K
Details
Sorry about that, I chose the wrong file from the directory (2.99 KB, text/plain)
2013-05-29 10:01 UTC, Sung K
Details
bxc12441.cs (2.61 KB, application/octet-stream)
2013-05-29 14:31 UTC, Jonathan Pryor
Details

Description Sung K 2013-05-28 19:03:50 UTC
The attached source code shows a code snippet that will always throw this error.

An explanation of what the code is attempting to do:
TestBase class is used as our custom object that we will be attempting to serialize and de-serialize.  Within this class, there are DataMembers that are defined through very simple property accessors.  From our testing, we realized that there was an issue that occurs when using Template types, so an example of that has been included in the example.  The basic structure of this class is based on code that we use internally for another system that works completely fine in .NET.

After our test object has been instantiated it is serialized and de-serialized, once again the sequence of events that we use for this process works exactly as we would expect it to in a purely .NET environment.

The exception is thrown on the de-serialization of our custom object.


I mentioned earlier that this occurs for varying Nullable; meaning if instead of using a Nullable BOOL and a Nullable INT, we had used two Nullable INTs then this error does that occur.

We also tested this idea against having only one Nullable type; we tried a wide variety of datatypes, including: byte, bool, short, int, long, DateTime, decimal.  Aslong as there is only one Nullable type, xamarin is able to de-serialize it as expected.


Notes about the attachment: To compile the attached Android activity, be sure to include reference to System.Runtime.Serialization
Comment 1 Sung K 2013-05-28 19:04:46 UTC
Created attachment 4031 [details]
An example Activity that will attempt to serialize and deserialize a custom object
Comment 2 Chris Hardy [MSFT] 2013-05-28 19:28:24 UTC
It looks like you've just attached a sln file directly, is it possible to zip up a full project that we can use to reproduce this problem? Thanks
Comment 3 Sung K 2013-05-29 10:01:43 UTC
Created attachment 4038 [details]
Sorry about that, I chose the wrong file from the directory
Comment 4 Jonathan Pryor 2013-05-29 14:31:41 UTC
Created attachment 4041 [details]
bxc12441.cs
Comment 5 Jonathan Pryor 2013-05-29 14:36:24 UTC
This is a Mono/WCF bug, not a Xamarin.Android bug.

To reproduce, see the attached bxc12441.cs (Attachment #4041 [details]), which removes the Android dependencies.

Compile:

    $ mcs -r:System.Xml.dll -r:System.Runtime.Serialization.dll bxc12441.cs

Expected results: the same as .NET (XML reformatted for display):

    > .\bxc12441.exe
Serialized XML:
<TestBase xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <boolValueClassTest>
    <_CurrentValue i:nil="true" />
  </boolValueClassTest>
  <intValueClassTest>
    <_CurrentValue>9999</_CurrentValue>
  </intValueClassTest>
</TestBase>

Actual results: (XML reformatted for display):

    $ mono bxc12441.exe
Serialized XML:
<TestBase xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <boolValueClassTest>
    <_CurrentValue i:nil="true" />
    <_OriginalValue i:nil="true" />
  </boolValueClassTest>
  <intValueClassTest>
    <_CurrentValue>9999</_CurrentValue>
    <_OriginalValue i:nil="true" />
  </intValueClassTest>
</TestBase>

> Unhandled Exception:
> System.FormatException: 9999 is not a valid boolean value
>   at System.Xml.XmlConvert.ToBoolean (System.String s) [0x00000] in <filename unknown>:0 
>   at System.Runtime.Serialization.KnownTypeCollection.PredefinedTypeStringToObject (System.String s, System.String name, System.Xml.XmlReader reader) [0x00000] in <filename unknown>:0 
>   at System.Runtime.Serialization.XmlFormatterDeserializer.DeserializePrimitive (System.Type type, System.Xml.XmlReader reader, System.Xml.XmlQualifiedName qname) [0x00000] in <filename unknown>:0 
>   at System.Runtime.Serialization.XmlFormatterDeserializer.Deserialize (System.Type type, System.Xml.XmlReader reader) [0x00000] in <filename unknown>:0 
>   at System.Runtime.Serialization.SerializationMap.DeserializeContent (System.Xml.XmlReader reader, System.Runtime.Serialization.XmlFormatterDeserializer deserializer, System.String id, Boolean empty) [0x00000] in <filename unknown>:0 
>   at System.Runtime.Serialization.SerializationMap.DeserializeContent (System.Xml.XmlReader reader, System.Runtime.Serialization.XmlFormatterDeserializer deserializer, System.String id) [0x00000] in <filename unknown>:0 
>   at System.Runtime.Serialization.SerializationMap.DeserializeObject (System.Xml.XmlReader reader, System.Runtime.Serialization.XmlFormatterDeserializer deserializer) [0x00000] in <filename unknown>:0 
>   at System.Runtime.Serialization.XmlFormatterDeserializer.DeserializeByMap (System.Xml.XmlQualifiedName name, System.Type type, System.Xml.XmlReader reader) [0x00000] in <filename unknown>:0 
>   at System.Runtime.Serialization.XmlFormatterDeserializer.Deserialize (System.Type type, System.Xml.XmlReader reader) [0x00000] in <filename unknown>:0 
>   at System.Runtime.Serialization.SerializationMap.DeserializeContent (System.Xml.XmlReader reader, System.Runtime.Serialization.XmlFormatterDeserializer deserializer, System.String id, Boolean empty) [0x00000] in <filename unknown>:0 
>   at System.Runtime.Serialization.SerializationMap.DeserializeContent (System.Xml.XmlReader reader, System.Runtime.Serialization.XmlFormatterDeserializer deserializer, System.String id) [0x00000] in <filename unknown>:0 
>   at System.Runtime.Serialization.SerializationMap.DeserializeObject (System.Xml.XmlReader reader, System.Runtime.Serialization.XmlFormatterDeserializer deserializer) [0x00000] in <filename unknown>:0 
>   at System.Runtime.Serialization.XmlFormatterDeserializer.DeserializeByMap (System.Xml.XmlQualifiedName name, System.Type type, System.Xml.XmlReader reader) [0x00000] in <filename unknown>:0 
>   at System.Runtime.Serialization.XmlFormatterDeserializer.Deserialize (System.Type type, System.Xml.XmlReader reader) [0x00000] in <filename unknown>:0 
>   at System.Runtime.Serialization.XmlFormatterDeserializer.Deserialize (System.Xml.XmlReader reader, System.Type declaredType, System.Runtime.Serialization.KnownTypeCollection knownTypes, IDataContractSurrogate surrogate, System.Runtime.Serialization.DataContractResolver resolver, System.Runtime.Serialization.DataContractResolver defaultResolver, System.String name, System.String ns, Boolean verifyObjectName) [0x00000] in <filename unknown>:0 
>   at System.Runtime.Serialization.DataContractSerializer.ReadObject (System.Xml.XmlDictionaryReader reader, Boolean verifyObjectName) [0x00000] in <filename unknown>:0 
>   at System.Runtime.Serialization.XmlObjectSerializer.ReadObject (System.Xml.XmlDictionaryReader reader) [0x00000] in <filename unknown>:0 
>   at System.Runtime.Serialization.DataContractSerializer.ReadObject (System.Xml.XmlReader reader) [0x00000] in <filename unknown>:0 
>   at Test.Serialization () [0x00000] in <filename unknown>:0 
>   at Test.Main () [0x00000] in <filename unknown>:0 
> [ERROR] FATAL UNHANDLED EXCEPTION: System.FormatException: 9999 is not a valid boolean value
>   at System.Xml.XmlConvert.ToBoolean (System.String s) [0x00000] in <filename unknown>:0 
>   at System.Runtime.Serialization.KnownTypeCollection.PredefinedTypeStringToObject (System.String s, System.String name, System.Xml.XmlReader reader) [0x00000] in <filename unknown>:0 
>   at System.Runtime.Serialization.XmlFormatterDeserializer.DeserializePrimitive (System.Type type, System.Xml.XmlReader reader, System.Xml.XmlQualifiedName qname) [0x00000] in <filename unknown>:0 
>   at System.Runtime.Serialization.XmlFormatterDeserializer.Deserialize (System.Type type, System.Xml.XmlReader reader) [0x00000] in <filename unknown>:0 
>   at System.Runtime.Serialization.SerializationMap.DeserializeContent (System.Xml.XmlReader reader, System.Runtime.Serialization.XmlFormatterDeserializer deserializer, System.String id, Boolean empty) [0x00000] in <filename unknown>:0 
>   at System.Runtime.Serialization.SerializationMap.DeserializeContent (System.Xml.XmlReader reader, System.Runtime.Serialization.XmlFormatterDeserializer deserializer, System.String id) [0x00000] in <filename unknown>:0 
>   at System.Runtime.Serialization.SerializationMap.DeserializeObject (System.Xml.XmlReader reader, System.Runtime.Serialization.XmlFormatterDeserializer deserializer) [0x00000] in <filename unknown>:0 
>   at System.Runtime.Serialization.XmlFormatterDeserializer.DeserializeByMap (System.Xml.XmlQualifiedName name, System.Type type, System.Xml.XmlReader reader) [0x00000] in <filename unknown>:0 
>   at System.Runtime.Serialization.XmlFormatterDeserializer.Deserialize (System.Type type, System.Xml.XmlReader reader) [0x00000] in <filename unknown>:0 
>   at System.Runtime.Serialization.SerializationMap.DeserializeContent (System.Xml.XmlReader reader, System.Runtime.Serialization.XmlFormatterDeserializer deserializer, System.String id, Boolean empty) [0x00000] in <filename unknown>:0 
>   at System.Runtime.Serialization.SerializationMap.DeserializeContent (System.Xml.XmlReader reader, System.Runtime.Serialization.XmlFormatterDeserializer deserializer, System.String id) [0x00000] in <filename unknown>:0 
>   at System.Runtime.Serialization.SerializationMap.DeserializeObject (System.Xml.XmlReader reader, System.Runtime.Serialization.XmlFormatterDeserializer deserializer) [0x00000] in <filename unknown>:0 
>   at System.Runtime.Serialization.XmlFormatterDeserializer.DeserializeByMap (System.Xml.XmlQualifiedName name, System.Type type, System.Xml.XmlReader reader) [0x00000] in <filename unknown>:0 
>   at System.Runtime.Serialization.XmlFormatterDeserializer.Deserialize (System.Type type, System.Xml.XmlReader reader) [0x00000] in <filename unknown>:0 
>   at System.Runtime.Serialization.XmlFormatterDeserializer.Deserialize (System.Xml.XmlReader reader, System.Type declaredType, System.Runtime.Serialization.KnownTypeCollection knownTypes, IDataContractSurrogate surrogate, System.Runtime.Serialization.DataContractResolver resolver, System.Runtime.Serialization.DataContractResolver defaultResolver, System.String name, System.String ns, Boolean verifyObjectName) [0x00000] in <filename unknown>:0 
>   at System.Runtime.Serialization.DataContractSerializer.ReadObject (System.Xml.XmlDictionaryReader reader, Boolean verifyObjectName) [0x00000] in <filename unknown>:0 
>   at System.Runtime.Serialization.XmlObjectSerializer.ReadObject (System.Xml.XmlDictionaryReader reader) [0x00000] in <filename unknown>:0 
>   at System.Runtime.Serialization.DataContractSerializer.ReadObject (System.Xml.XmlReader reader) [0x00000] in <filename unknown>:0 
>   at Test.Serialization () [0x00000] in <filename unknown>:0 
>   at Test.Main () [0x00000] in <filename unknown>:0 

Note that the XML differs, as well as the exception from mono.

Note You need to log in before you can comment on or make changes to this bug.