Bug 2262 - DataContractSerializer fails to deserialize custom DataContract with string and Dictionary<string,string>
Summary: DataContractSerializer fails to deserialize custom DataContract with string a...
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: WCF assemblies (show other bugs)
Version: 2.10.x
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2011-11-30 02:39 UTC by ju cheng
Modified: 2011-11-30 22:02 UTC (History)
1 user (show)

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


Description ju cheng 2011-11-30 02:39:44 UTC
//The following code works fine on .NET 4.0, but crashes on mono

using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.IO;

namespace InitInCtor
    public class Data
        public string Zero { get; set; }

        public Dictionary<string, string> Item { get; set; }

        public Data()
            Item = new Dictionary<string, string>();

    class Program
        static void Main(string[] args)
            var ser = new DataContractSerializer(typeof(Data));
            using (var mem = new MemoryStream())
                ser.WriteObject(mem, new Data());
                mem.Seek(0, SeekOrigin.Begin);
Comment 1 ju cheng 2011-11-30 22:02:26 UTC
If I modify the code in either way describe as following, the code will work: 
1. Give Item a larger Order and make sure it's serialized after Zero
2. Remove dictionary initialization code in constructor.
But these two ways break compatibility.

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