title: Serialization of enum fails
body: <p>I use .NET 3.5 for this.</p>
  
  <p>I have an enum:</p>
  
  <pre><code>[System.SerializableAttribute()]
  public enum MyEnum
  {
      [System.Xml.Serialization.XmlEnumAttribute("035")]
      Item1,
      Item2
  }
  </code></pre>
  
  <p>I use this enum in a class:</p>
  
  <pre><code>[System.SerializableAttribute()]
  public class Employee
  {
      public int Id { get; set; }
      public string Name { get; set; }
      public MyEnum MyEnum { get; set; }
  }
  </code></pre>
  
  <p>Now I want to create a new Eplomyee-instance, set the MyEnum-property by casting it from a string.
  Then serialize it and save it in a file.</p>
  
  <pre><code>Employee bob = new Employee() {Id = 1, Name = "Bob"};
  bob.MyEnum = (MijnEnum)Enum.Parse(typeof(MyEnum), string.Format(CultureInfo.InvariantCulture, "{0}", "035"));
  
  XmlSerializer serializer = new XmlSerializer(typeof(Employee));
  FileInfo fi = new FileInfo(@"C:\myfile.xml");
  using (FileStream stream = fi.OpenWrite())
  {
      XmlWriterSettings xmlWriterSettings = new XmlWriterSettings { Encoding = Encoding.UTF8, OmitXmlDeclaration = true, Indent = true };
      using (XmlWriter writer = XmlWriter.Create(stream, xmlWriterSettings))
      {
          serializer.Serialize(writer, bob); // this is place where it goes wrong
      }
  }
  </code></pre>
  
  <p>If I debug this, I see that the value of <code>bob.MyEnum</code> is <strong>35</strong></p>
  
  <p>When I try to serialize, I get an exception:</p>
  
  <blockquote>
    <p>There was an error generating the XML document.</p>
    
    <p>Instance validation error: '35' is not a valid value for
    WindowsFormsApplication.MyEnum.</p>
  </blockquote>
  
  <p>What is going wrong and how can I solve this?</p>