title: The Invulnerable XMLException
body: <h2>Background</h2>
  <p>I serialize a very large <code>List&lt;string&gt;</code> using this code:</p>
  <pre><code>public static string SerializeObjectToXML&lt;T&gt;(T item)
  {
      XmlSerializer xs = new XmlSerializer(typeof(T));
      using (StringWriter writer = new StringWriter())
      {
          xs.Serialize(writer, item);
          return writer.ToString();
      }
  }
  </code></pre>
  <p>And deserialize it using this code:</p>
  <pre><code>public static T DeserializeXMLToObject&lt;T&gt;(string xmlText)
  {
      if (string.IsNullOrEmpty(xmlText)) return default(T);
      XmlSerializer xs = new XmlSerializer(typeof(T));
      using (MemoryStream memoryStream = new MemoryStream(new UnicodeEncoding().GetBytes(xmlText.Replace((char)0x1A, ' '))))
      using (XmlTextReader xsText = new XmlTextReader(memoryStream))
      {
          xsText.Normalization = true;
          return (T)xs.Deserialize(xsText);
      }
  }
  </code></pre>
  <p>But I get this exception when I deserialize it:</p>
  <blockquote>
  <p><strong>XMLException</strong>: There is an error in XML document (217388, 15). '[]', hexadecimal value 0x1A, is an invalid character. Line 217388, position 15.</p>
  <p><em>at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)</em></p>
  <p><em>at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader)</em></p>
  </blockquote>
  <h2>Question</h2>
  <p><strong>Why is the</strong> <code>xmlText.Replace((char)0x1A, ' ')</code> <strong>line not working</strong>, what witchery is this?</p>
  <h2>Some Constraints</h2>
  <ul>
  <li>My code is in C#, framework 4, built in VS2010 Pro.</li>
  <li>I can't view the value of xmlText in debug mode because the <code>List&lt;string&gt;</code> is too big and the watch windows just displays the <code> Unable to evaluate the expression. Not enough storage is available to complete this operation.</code> error message.</li>
  </ul>