title: Xml Deserialize works with .Net 4.5.2, breaks with 4.6: xmlns was not expected
body: <p>We have a C# project that deserializes large XML files and has been working fine with .Net 4.5.2.  </p>
  
  <p>As soon as we upgrading the project to .Net 4.6 we get the following exception on the xmlserializer.Deserialize call:</p>
  
  <pre><code>System.InvalidOperationException
    HResult=0x80131509
    Message=There is an error in XML document (1, 2).
  Inner Exception 1:
  InvalidOperationException: &lt;AccountTransferRequest xmlns='http://at.dsh.cms.gov/exchange/1.0'&gt; was not expected.
  </code></pre>
  
  <p>C# code:</p>
  
  <pre><code>    string filename = @"C:\CARES_TFS\FIPS140\Cares\Cares.Test\TestData\FFM Sync\FFMStateAidCat38.xml";
      var xmlReader = new XmlTextReader(new FileStream(filename, FileMode.Open));
      var xmlserializer = new XmlSerializer(typeof(AccountTransferRequestPayloadType));
      var obj = xmlserializer.Deserialize(xmlReader) as AccountTransferRequestPayloadType;
  </code></pre>
  
  <p>The C# class we are deserializing into to is auto-generated, and looks like the following:</p>
  
  <pre><code>[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.6.1087.0")]
  [System.SerializableAttribute()]
  [System.Diagnostics.DebuggerStepThroughAttribute()]
  [System.ComponentModel.DesignerCategoryAttribute("code")]
  [System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://at.dsh.cms.gov/extension/1.0")]
  [System.Xml.Serialization.XmlRoot("AccountTransferRequest", IsNullable = false, Namespace = "http://at.dsh.cms.gov/exchange/1.0")]
  public partial class AccountTransferRequestPayloadType : ComplexObjectType { ... }
  </code></pre>
  
  <p>The following is the first line of the xml file:</p>
  
  <pre><code>&lt;exch:AccountTransferRequest 
      ext:atVersionText="2.4" 
      xsi:schemaLocation="http://at.dsh.cms.gov/exchange/1.0  ../XSD/XMLschemas/constraint/exchange/ExchangeModel.xsd"  
      xmlns:exch="http://at.dsh.cms.gov/exchange/1.0" 
      xmlns:ext="http://at.dsh.cms.gov/extension/1.0" 
      xmlns:hix-core="http://hix.cms.gov/0.1/hix-core" 
      xmlns:hix-ee="http://hix.cms.gov/0.1/hix-ee" 
      xmlns:hix-pm="http://hix.cms.gov/0.1/hix-pm" 
      xmlns:nc="http://niem.gov/niem/niem-core/2.0" 
      xmlns:s="http://niem.gov/niem/structures/2.0" 
      xmlns:scr="http://niem.gov/niem/domains/screening/2.1" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
  </code></pre>
  
  <p>Things we've tried:</p>
  
  <p>1) Adding:</p>
  
  <pre><code>  &lt;system.xml.serialization&gt;
      &lt;xmlSerializer useLegacySerializerGeneration="true" /&gt;
    &lt;/system.xml.serialization&gt;
  </code></pre>
  
  <p>to the app.config</p>
  
  <p>2) Removing the namespaces in the XML file and the class attributes</p>
  
  <p>3) Removing the reference to the 4.6 version System.Xml.dll and adding a reference to the 4.5.2 version of System.Xml.dll (while leaving the rest of the project at .Net 4.6).  THIS ACTUALLY WORKED, but not the solution we'd like</p>