Bug 18908 - System.Xml.Serialization.XmlSerializer.Deserialize returns different results on Mac vs Windows
Summary: System.Xml.Serialization.XmlSerializer.Deserialize returns different results ...
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.XML ()
Version: 3.4.0
Hardware: PC Mac OS
: Normal major
Target Milestone: Untriaged
Assignee: marcos.henrich
URL:
Depends on:
Blocks:
 
Reported: 2014-04-09 16:11 UTC by John Miller [MSFT]
Modified: 2014-09-29 03:52 UTC (History)
4 users (show)

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


Attachments
Repro Project (51.28 KB, application/zip)
2014-04-09 16:11 UTC, John Miller [MSFT]
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description John Miller [MSFT] 2014-04-09 16:11:53 UTC
Created attachment 6541 [details]
Repro Project

The Deserialize(type) method returns incorrect results when ran on Mac OSX with Mono vs running the same application in VS on Windows. 

Steps to Reproduce: 

* Run the attached sample project
* Observe the value of "o" on line 48 were Deserialize is called. 

Result:

* The "TextualValue" property of that object has the value "255.255.255.255". 

Expected Results:

* The "TextualValue" property of that object should have the value "172.31.6.66". 

Additional Info:

* On Windows, the same application produces the expected results above. 

Example Code:

            SerializableIPAddress sip = new SerializableIPAddress(new byte[4] { 172, 31, 6, 66 });

            IPAddress ip = new IPAddress(new byte[4] { 172, 31, 6, 66 });


            object o = sip;
            string serializedData = string.Empty;
            using (MemoryStream mstream = new MemoryStream())
            {
                using (XmlTextWriter writer = new XmlTextWriter(mstream, Encoding.ASCII))
                {
                    XmlSerializer serializer = new XmlSerializer(o.GetType());
                    serializer.Serialize(writer, o);

                    serializedData = Encoding.ASCII.GetString(mstream.GetBuffer());
                }
            }



            using (MemoryStream mstream = new MemoryStream(Encoding.ASCII.GetBytes(serializedData)))
            {
                using (XmlTextReader reader = new XmlTextReader(mstream))
                {
                    XmlSerializer deserializer = new XmlSerializer(typeof(SerializableIPAddress));
                    o = deserializer.Deserialize(reader); // Incorrect value with Mono
                }
            }
        }
Comment 1 John Miller [MSFT] 2014-06-06 12:51:07 UTC
Additional Info:

    Another case of a similar issue desearlizing a class generated with Xsd2Code. Attached is a test case with both an Android and Console project. 

Steps to reproduce (using private attachment):

   1. Run the console project with Mono.
       1.a The "forwardToPhoneNumber" property will be null. 
   2. Run the console project with .NET on Windows.
       2.a The "forwardToPhoneNumber" property will be correctly deserialized.
Comment 3 marcos.henrich 2014-09-26 05:55:42 UTC
Hi John,

Thank you for the detailed bug report.

The pull request for this issue can be found in the link below.
https://github.com/mono/mono/pull/1312
Comment 4 marcos.henrich 2014-09-29 03:52:37 UTC
Fixed in master a59c434f46b2f08c8ddda5b78f601ab9c8dc51ab.
https://github.com/mono/mono/commit/a59c434f46b2f08c8ddda5b78f601ab9c8dc51ab