title: Public IDictionary member of ViewModel class will not serialize via DataContractSerializer
body: <p>I have a class that's my view model for a windows 8.1 universal application. I want to be able to serialize / deserialize this class as necessary. I have this working with the exception of the <code>IDictionary</code> public property. This property is being skipped. When I explicitly tell the <code>DataContractSerializer</code> to serialized by itself, it works as expected.</p>
  
  <p>Why is it not being picked up by the <code>DataContractSerializer</code> when serializing the view model class? I have all the <code>KnowType</code> issues worked out as you'll see when I serialize the <code>DataDictionary</code> directly.</p>
  
  <p>Here is the class in question</p>
  
  <pre><code>[KnownType( typeof( ViewModel ) )]
  public class AViewModel : ViewModelBase
  {
        public ViewModel()
        {
           DataDictionary = new Dictionary&lt;double, IData&gt;();
           SaveCommand = new RelayCommand( () =&gt; Save() );
           LoadCommand = new RelayCommand( () =&gt; Load() );
        }
  
        private string _firstName;
        public string FirstName { get { return _firstName; } set { Set( () =&gt; FirstName, ref _firstName, value ); } }
  
        private string _lastName;
        public string LastName { get { return _lastName; } set { Set( () =&gt; LastName, ref _lastName, value ); } }
  
        private IDictionary&lt;double, IData&gt; _dataDictionary;
        public IDictionary&lt;double, IData&gt; DataDictionary { get { return _dataDictionary; } private set { _dataDictionary = value; } }
  
        public ICommand SaveCommand { get; private set; }
        public ICommand LoadCommand { get; private set; }
  
        private async void Save()
        {
          //logic will go here, example in unit test below
        }
  }
  </code></pre>
  
  <p>Here are the sub classes related to the <code>IData</code></p>
  
  <pre><code>public interface IData
  {
     string Type { get; set; }
  }
  
  [KnownType( typeof( BlueData ) )]
  public class BlueData : IData
  {
     public string String1 { get; set; }
     public string Type { get; set; }
  }
  
  [KnownType( typeof( GreenData ) )]
  public class GreenData : IData
  {
     public string Type { get; set; }
     public string String1 { get; set; }
  }
  </code></pre>
  
  <p>Here is the code that I'm using to build the serialization</p>
  
  <pre><code>ViewModel model = new ViewModel();
  model.FirstName = "First";
  model.LastName = "Last";
  model.DataDictionary.Add( 1.2, new BlueData { String1 = "TestBlueData", Type = "BlueData" } );
  
  MemoryStream memoryStream = new MemoryStream();
  DataContractSerializer serializer = new DataContractSerializer( typeof( ViewModel ) );
  serializer.WriteObject( memoryStream, model );
  
  memoryStream.Seek( 0, SeekOrigin.Begin );
  
  string xml;
  using ( StreamReader reader = new StreamReader( memoryStream ) )
  {
      xml = reader.ReadToEnd();
  }
  </code></pre>
  
  <p>Here is the xml output I'm getting from the above code</p>
  
  <pre><code>&lt;ViewModel xmlns="http://schemas.datacontract.org/2004/07/ApplicationNamespace.ViewModel" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt;&lt;FirstName&gt;First&lt;/FirstName&gt;&lt;LastName&gt;Last&lt;/LastName&gt;&lt;/ViewModel&gt;
  </code></pre>
  
  <p>When I call <code>DataContractSerializer</code> on <code>model.DataDictionary</code> directly, I get the following</p>
  
  <pre><code>&lt;ArrayOfKeyValueOfdoubleanyType xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt;&lt;KeyValueOfdoubleanyType&gt;&lt;Key&gt;1.2&lt;/Key&gt;&lt;Value i:type="a:BlueData" xmlns:a="http://schemas.datacontract.org/2004/07/ApplicationNamespace"&gt;&lt;a:String1&gt;TestBlueData&lt;/a:String1&gt;&lt;a:Type&gt;BlueData&lt;/a:Type&gt;&lt;/Value&gt;&lt;/KeyValueOfdoubleanyType&gt;&lt;/ArrayOfKeyValueOfdoubleanyType&gt;
  </code></pre>