title: Save a Dictionary with classes to file
body: <p>Hello i have another question. First of all i have following classes:</p>
  
  <pre><code> {
          [DataMember]
  [XmlElement(ElementName = "RecipeBook")]
  public Dictionary&lt;string, Recipe&gt; DRezeptbuch = new Dictionary&lt;string, Recipe&gt;(); 
  }
  </code></pre>
  
  <hr>
  
  <pre><code>    public class Recipe
  {
      [XmlElement(ElementName = "Name")]
      public string Name { get; set; }
  
      [XmlElement(ElementName = "Size")]
      public int? Size { get; set; }
  
      [XmlElement(ElementName = "Ingredients")]
      public List&lt;Ingredient&gt; Ingredients { get; set; }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>    public class Ingredient
  {
      [XmlElement(ElementName = "Name")]
      public string Name { get; set; }
  
      [XmlElement(ElementName = "Amount")]
      public decimal amount;
  
      [XmlElement(ElementName = "Unit")]
      public Units.Unit unit;
  
      [XmlElement(ElementName = "Specification")]
      public List&lt;Units.Specification&gt; specification;
  
      [XmlElement(ElementName = "Category")]
      public Units.Category category;
  }
  </code></pre>
  
  <p>So im filling the "DRezeptbuch" and want to write this to a file. I tried xmlserialization but i failed. </p>
  
  <pre><code>            //var serializer = new XmlSerializer(dRezeptbuch.GetType());
          //using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
          //{
          //    serializer.Serialize(ms, dRezeptbuch);
          //    ms.Position = 0;
          //    xmlDoc.Load(ms);
          //    return xmlDoc.InnerXml;
          //}
  </code></pre>
  
  <p>Then i tried it with this DataContract thingy but i wont work either. </p>
  
  <pre><code>            var serializer = new DataContractSerializer(typeof(RecipeBook));
          string xmlString;
          using (var sw = new StringWriter())
          {
              using (var writer = new XmlTextWriter(sw))
              {
                  writer.Formatting = Formatting.Indented; // indent the Xml so it's human readable
                  serializer.WriteObject(writer, dRezeptbuch);
                  writer.Flush();
                  xmlString = sw.ToString();
  
              }
          }
  </code></pre>
  
  <p>so what should i do? 
  is there a good way to save this dictionary?</p>