Bug 11801 - DataContractSerializer: data serialized on MonoTouch is deserialized wrong on Win (IList<IIterface>)
Summary: DataContractSerializer: data serialized on MonoTouch is deserialized wrong on...
Status: RESOLVED INVALID
Alias: None
Product: iOS
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 6.0.x
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-04-16 05:51 UTC by Artur
Modified: 2017-01-25 17:44 UTC (History)
4 users (show)

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


Attachments
Small test console app. (26.34 KB, application/x-zip-compressed)
2017-01-25 17:16 UTC, Manuel de la Peña [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 Developer Community or GitHub 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 INVALID

Description Artur 2013-04-16 05:51:14 UTC
If I serialize data under MonoTouch and then try to deserialize on Win with .net framework the results differ.
The problem is that serialization of List<IItem> differs significantly.

The following are data structures:
namespace Tst
{

    public interface IItem
    {
    }
    [DataContract(Namespace = "Tst")]
    public class Item : IItem
    {
        [DataMember]
        public int A { get; set; }
    }
    [DataContract(Namespace = "Tst"), KnownType(typeof(Item))]
    public class Data
    {
        [DataMember]
        public IList<IItem> Items1 { get; set; }
    }
    [TestFixture]
    public class Tests2
    {
        [Test]
        public void Test()
        {
            var value = new Data()
            {
                Items1 = new List<IItem>() { new Item() { A = 1 } },
            };
            var sb = new StringBuilder();
            var xmlWriter = new XmlTextWriter(new StringWriter(sb));
            DataContractSerializer dataContractSerializer = new DataContractSerializer(typeof(Data));
            dataContractSerializer.WriteObject(xmlWriter, value);
            Console.WriteLine(sb.ToString());

            var serializedStringFromMonoTouch =
                "<Data xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"Tst\"><Items1 xmlns:d2p1=\"http://schemas.datacontract.org/2004/07/Tst\"><d2p1:IItem i:type=\"Item\"><A>1</A></d2p1:IItem></Items1></Data>";
            var obj = (Data)dataContractSerializer.ReadObject(new XmlTextReader(new StringReader(dt)));
            Assert.AreEqual(obj.Items1.Count, 1);
        }
    }



Here's the string when serialized on Windows with .Net framework:
<Data xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="Tst"><Items1 xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"><d2p1:anyType i:type="Item"><A>1</A></d2p1:anyType></Items1></Data>
String when serialized under MonoTouch is given within a test.

Assertion in a test fails.
Comment 1 Manuel de la Peña [MSFT] 2017-01-11 11:10:55 UTC
Hello,

Running the example code on a Mac OS with XS and Mono 4.6.2 (mono-4.6.0-branch/ac9e222) (64-bit) I get the following serialisation:

<Data xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="Tst"><Items1 xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"><d2p1:anyType i:type="Item"><A>1</A></d2p1:anyType></Items1></Data>

While on a Windows Machine with VS Studio I get the following one:

<Data xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="Tst"><Items1><Item><A>1</A></Item></Items1></Data>

Looks like even when the Namespace value is passed to the DataContract attributes the generated code does not remove them.
Comment 2 Manuel de la Peña [MSFT] 2017-01-25 17:16:55 UTC
Created attachment 19479 [details]
Small test console app.
Comment 3 Manuel de la Peña [MSFT] 2017-01-25 17:44:40 UTC
The above test was done using mono 4.6, with mono 4.8 we share the serialisation with .Net core and the following is returned from the attached example app:

<Data xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="Tst"><Items1><Item><A>1</A></Item></Items1></Data>

Therefore the result is the same and will close the bug as invalid.