title: C# Attribute XmlIgnore and XamlWriter class - XmlIgnore not working
body: <p>I have a class, containing a property <code>Brush MyBrush</code> marked as <code>[XmlIgnore]</code>. Nevertheless it is serialized in the stream causing trouble when trying to read via <code>XamlReader</code>.</p>
  
  <p>I did some tests, e.g. when changing the visibility of the Property (to internal) it is gone in the stream. Unfortunately I cannot do this in my particular scenario.</p>
  
  <ol>
  <li>Did anybody have the same issue and?</li>
  <li>Do you see any way to work around this?</li>
  </ol>
  
  <p>Remark: C# 4.0 as far I can tell</p>
  
  <p>This is a method from my Unit Test where I do test the <code>XamlSerialization</code>:</p>
  
  <pre><code>            // buffer to a StringBuilder
              StringBuilder sb = new StringBuilder();
              XmlWriter writer = XmlWriter.Create(sb, settings);
              XamlDesignerSerializationManager manager = new XamlDesignerSerializationManager(writer) {XamlWriterMode = XamlWriterMode.Expression};
  
              XamlWriter.Save(testObject, manager);
              xml = sb.ToString();
              Assert.IsTrue(!String.IsNullOrEmpty(xml) &amp;&amp; !String.IsNullOrEmpty(xml), "Xaml Serialization failed for " + testObject.GetType() + " no xml string available");
  
              xml = sb.ToString();
              MemoryStream ms = xml.StringToStream();
              object root = XamlReader.Load(ms);
              Assert.IsTrue(root != null, "After reading from MemoryStream no result for Xaml Serialization");
  </code></pre>
  
  <p>In one of my classes I use the Property <code>Brush</code>. In the above code this Unit Tests fails because a <code>Brush</code> object (not serializable) is the value. When I remove the Setter (as below), the Unit Test passes.</p>
  
  <p>Using the <code>XmlWriter</code> (basically same test as above) it works. In the <code>StringBuffer sb</code> I can see that <code>Property Brush</code> is serialized when the Setter is there and not when removed (most likely another check ignoring the Property because of no setter). Other Properties with <code>[XmlIgnore]</code> are ignored as intended.</p>
  
  <pre><code>    [XmlIgnore]
      public Brush MyBrush
      {
          get { ..... }
          // removed because of problem with Serialization
          // set { ... }
      }
  </code></pre>