title: How to stop .NET from encoding an XML string with XML.Serialization
body: <p>I am working with some Xml Serialization in ASP.NET 2.0 in a web service.  The issue is that I have an element which is defined such as this:</p>
  
  <pre><code>&lt;System.Xml.Serialization.XmlElementAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable:=True)&gt; _
  Public Property COMMENTFIELD() As String
      Get
          Return CommentField ' This is a string
      End Get
      Set(ByVal value as String)
          CommentField = value
      End Set
  End Property
  </code></pre>
  
  <p>Elsewhere in code I am constructing a comment and appending &#xA; as a line-break (according to the rules of the web service we are submitting to) between each 'comment', like this: (Please keep in mind that &#xA; is a valid XML entity representing character 10 (Line Feed I believe).</p>
  
  <pre><code>XmlObject.COMMENTFIELD = sComment1 &amp; "&amp;#xA;" &amp; sComment2
  </code></pre>
  
  <p>The issue is that .NET tries to do us a favor and encode the &amp; in the comment string which ends up sending the destination web service this: <code>&amp;amp;#xA;</code>, which obviously isn't what we want.</p>
  
  <p>Here is what currently happens:</p>
  
  <pre><code>XmlObject.COMMENTFIELD = sComment1 &amp; "&amp;#xA;" &amp; sComment2
  </code></pre>
  
  <p>Output:  </p>
  
  <pre><code>&lt;COMMENTFIELD&gt;comment1 &amp;amp;#xA comment2&lt;/COMMENTFIELD&gt;
  </code></pre>
  
  <p>Output I NEED:  </p>
  
  <pre><code>&lt;COMMENTFIELD&gt;comment1 &amp;#xA; comment2&lt;/COMMENTFIELD&gt;
  </code></pre>
  
  <p><strong>The Question Is:</strong> How do I force the .NET runtime to not try and do me any favors in regards to encoding data that I already know is XML compliant and escaped already (btw sComment1 and sComment2 would already be escaped).  I'm used to taking care of my XML, not depending on something magical that happens to escape all my data behind my back!</p>
  
  <p>I need to be able to pass valid XML into the COMMENTFIELD property without .NET encoding the data I give it (as it is already XML).  I need to know how to tell .NET that the data it is receiving is an XML String, not a normal string that needs escaped.</p>