title: Asp.net MVC4 Web API XML serialization ignores public properties
body: <p>I'm using asp.net mvc4 web api. I've got some classes generated by Devart Entity Developer and they have following structure:</p>
  
  <pre><code>[Serializable]
  [XmlRoot("Test")]
  [JsonObject(MemberSerialization.OptIn)]
  public class Test
  {
      [XmlAttribute("property1")]
      [JsonProperty("property1")]
      public int Property1
      {
          get { return _Property1; }
          set
          {
              if (_Property1 != value)
              {
                  _Property1 = value;
              }
          }
      }
      private int _Property1;
  
      [XmlAttribute("property2")]
      [JsonProperty("property2")]
      public int Property2
      {
          get { return _Property2; }
          set
          {
              if (_Property2 != value)
              {
                  _Property2 = value;
              }
          }
      }
      private int _Property2;
  }
  </code></pre>
  
  <p>I have test controller for such class:</p>
  
  <pre><code>public class TestController : ApiController
  {
      private List&lt;Test&gt; _tests = new List&lt;Test&gt;() ;
  
      public TestController()
      {
          _tests.Add(new Test() { Property1 = 1, Property2 = 2 });
          _tests.Add(new Test() { Property1 = 3, Property2 = 4 });
      }
  
      public IEnumerable&lt;Test&gt; Get()
      {
          return _tests;
      }
  }
  </code></pre>
  
  <p>When I try to get test values in JSON format it returns correct response:</p>
  
  <pre><code>"[{"property1":1,"property2":2},{"property1":3,"property2":4}]"
  </code></pre>
  
  <p>But when I use XML format it serializes not public (<code>Property1</code>) but private properties (i.e. <code>_Property1</code>) and response look like:</p>
  
  <pre><code>&lt;ArrayOfTest xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/TestProject.Models.Data"&gt;
    &lt;Test&gt;
       &lt;_Property1&gt;1&lt;/_Property1&gt;
       &lt;_Property2&gt;2&lt;/_Property2&gt;
     &lt;/Test&gt;
     &lt;Test&gt;
       &lt;_Property1&gt;3&lt;/_Property1&gt;
       &lt;_Property2&gt;4&lt;/_Property2&gt;
     &lt;/Test&gt;
  &lt;/ArrayOfTest&gt;
  </code></pre>
  
  <p><strong>UPD:</strong> I've tried to add [NonSerialized] and [XmlIgnore] to private properties, but in this way xml output was empty, just: </p>
  
  <pre><code>&lt;ArrayOfTest xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/PeopleAirAPI.Models.Data"&gt;
    &lt;Test/&gt;
    &lt;Test/&gt;
  &lt;/ArrayOfTest&gt;
  </code></pre>
  
  <p>The question is how to force xml serializator to serialize public properties. To hide (ignore) that private properties is not a problem. I can't understand why it serializes that private properties at all, I've read in msdn docs and in other places that:</p>
  
  <blockquote>
    <p>XML serialization only serializes public fields and properties. </p>
  </blockquote>
  
  <p>Why in this case it acts contrary to docs?</p>