I am trying to deserialize XML from a TextReader and getting this error:
exception of type 'System.InvalidOperationException' occurred in Microsoft.GeneratedCode and wasn't handled before a managed/native boundary
Additional information: <Incident xmlns=''> was not expected.
The error occurs on the last line:
string dataXml = (string)dbDataReader["DataXML"];
XmlSerializer xmlSerializer = new XmlSerializer(typeof(Incident), new XmlRootAttribute { ElementName = "IncidentGet" });
System.IO.TextReader textReader = new System.IO.StringReader(dataXml);
incident = (Incident)xmlSerializer.Deserialize(textReader);
There are several tags in dataXML which are not mapped to any object at all. Does the deserializer just ignore them or do they cause the error? Or does the error come from some other source?
<incident>
<incidentnum>20180323905
<OccurredOn />
<reportedon>2019-02-01
<reportingofficer>TEST,TEST
<location>
<recnum>102953131
<house>4471
<street>TESTSTREETNAME2 PK
<CrossStreet />
<streetaddr>4471 TESTSTREETNAME2 PK
<city>TESTCITY
<state>TN
<zip>37013
<X />
<Y />
<Latitude />
<Longitude />
<county>019
<Validated />
<precinct>SOUTH
<RPA />
<Zone />
<countrycode>USA
<offenses>
<offense>
<code>120</code>
<description>ROBBERY - STREET-WEAPON
<offense>
<code>
<description>MATTEROFRECORD
</code><code>
</code><code>
<victims>
<victim>
<involvementnum>1
<race>B
<sex>F
<dob>1988-07-13
<name>TESTNAME2,TESTNAME3
<masterrecnum>71931912
<victimoffenses>
<victimoffense>
<offensecode>0003
<NibCode />
<offensename>MATTER OF RECORD
<victimnum>1
<linkofflrecnum>60036199
<linkoffloffenserec>13808415
<linkofflrecnum>6296009
<linkvictimrecnum>71931912
<relationships>
<relationship>
<victimnumber>1
<suspectnumber>1
<relation>17
<victimname>TESTNAME3 TESTNAME2
<suspectname>TESTNAME4 TESTNAME5
<linkincsusrecnum>6356248
<suspects>
<suspect>
<suspecttype>KNOWN
<involvementnum>1
<race>B
<sex>M
<dob>07/16/1987
<Age />
<name>TESTNAME5, TESTNAME4
<linkincsusrecnum>6356248
<source_rec>60036198
<callsforservice>
<callforservice>
<location>
<recnum>102524782
<House />
<Street />
<crossstreet>17TH AV N
<streetaddr>1600 TESTSTREETNAME ST
<city>NORTH
<State />
<Zip />
<X />
<Y />
<Latitude />
<Longitude />
<County />
<Validated />
<precinct>NORTH
<rpa>4475
<zone>613N
<CountryCode />
<callreceived>20180411 05:07
<tencode>41P
"
What I have tried:
I haven't tried much. I'm working within a team framework and can't change code without affecting the entire team. I'm just trying to nail down the exact source and nature of the error.