We have a C# project that deserializes large XML files and has been working fine with .Net 4.5.2.
As soon as we upgrading the project to .Net 4.6 we get the following exception on the xmlserializer.Deserialize call:
System.InvalidOperationException
HResult=0x80131509
Message=There is an error in XML document (1, 2).
Inner Exception 1:
InvalidOperationException: <AccountTransferRequest xmlns='http://at.dsh.cms.gov/exchange/1.0'> was not expected.
C# 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;
The C# class we are deserializing into to is auto-generated, and looks like the following:
[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 { ... }
The following is the first line of the xml file:
<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">
Things we've tried:
1) Adding:
<system.xml.serialization>
<xmlSerializer useLegacySerializerGeneration="true" />
</system.xml.serialization>
to the app.config
2) Removing the namespaces in the XML file and the class attributes
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