title: Difference between NonSerialized and Xml.Serialization.XmlIgnore?
body: <p>We're serializing/deserializing a class from XML but there are properties and fields in the class which we want to exclude.</p>
  
  <p>The <strong>System.NonSerialized</strong> and <strong>System.Xml.Serialization.XmlIgnore</strong> attributes seem to do the job but what's the difference between them? It seems we can use <strong>XmlIgnore</strong> on either properties or fields of the class. But <strong>NonSerialized</strong> can only be used on fields. Is there any reason not to use XmlIgnore in every case, and if so what's the purpose of the NonSerialized attribute and why the difference in usage?</p>
  
  <hr>
  
  <p>This is allowed:</p>
  
  <pre><code>&lt;System.NonSerialized()&gt; _
  Public Foo As String
  </code></pre>
  
  <hr>
  
  <p>This is allowed:</p>
  
  <pre><code>&lt;System.Xml.Serialization.XmlIgnore()&gt; _
  Public Foo As String
  </code></pre>
  
  <hr>
  
  <p>This is allowed:</p>
  
  <pre><code>&lt;System.Xml.Serialization.XmlIgnore()&gt; _
  Public Property Bar() As String
      Get
          Return _Bar
      End Get
      Set(ByVal value As String)
          _Bar = value
      End Set
  End Property
  </code></pre>
  
  <hr>
  
  <p>But this is not allowed:</p>
  
  <pre><code>&lt;System.NonSerialized()&gt; _
  Public Property Bar() As String
      Get
          Return _Bar
      End Get
      Set(ByVal value As String)
          _Bar = value
      End Set
  End Property
  </code></pre>