Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi guys,

I'm trying to deserialize data from a xml file, and the xml follows an xsd file. I also generated a C# file containing classes from the xsd file.

This code works fine:
C#
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas.Add(null, xsdfile);
XmlReader reader = XmlReader.Create(xmlfile, settings);
while(reader.Read()); // just to see if an exception occurs


So it makes me think the xml is valid according to the xsd file. (Moreover, I know for sure that it is valid)

But when I replace this line:
C#
while(reader.Read());


With this line:
C#
Dump dump = (Dump)serializer.Deserialize(reader);


I get this non managed exception:
There is an error in XML document (2, 2).
 ---> System.InvalidOperationException: <Dump xmlns=''> wasn't expected


But there is no
XML
<Dump xmlns=''>
in my xml, only a
XML
<Dump>
.

So I'm a bit lost.. Can you help?

Thanks !

What I have tried:

Searches but nothing helped so far :/
Posted
Updated 4-Oct-17 7:08am

1 solution

Try to add the following annotations to the top of your class, remember xml is case sensitive

[Serializable, XmlRoot("Dump")]
public partial class Dump
{
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900