XML, XSD, Designer.cs and the DataSet class in auto-generated code

  • Thread starter Thread starter Simple Samples
  • Start date Start date
S

Simple Samples

Guest
I am getting an InvalidOperationException with inner exception "<xmldata xmlns='http://tempuri.org/xmldata .xsd'> was not expected."

Let me back up. I wrote a WPF program for editing XML data in a GridView. I generated a XSD file using the XSD tool and I generated classes using the XSD tool. The generated classes are not derived from the DataSet class. I am using the XmlSerializer class to serialize out and deserialize in. That much was working. But now after making some changes I was getting the error I specified above. So I tried to generate a fresh schema and fresh classes from the XML data.

Here is where the plot thickens. In the Solution Explorer there is a Designer.cs file (I don't remember it being there before) with code for the data but it is derived from the DataSet class. That code uses the same names as the code that is generated that is not derived from the DataSet class.

Okay, so I decided to just change the namespace for the code I want to use. But then something changed the namespace name back to the project's namespace. Okay, well that seems to have been a one-time thing. Now the namespace name remains to be what I specified. The code compiles and executes. I am still getting the preceding error but I assume it is a separate problem.

Is there any way to get Visual Studio to not generate a Designer.cs file for the XSD file? Or can I configure it so that the code in the Designer.cs file is not for typed datasets? Okay, I see that in the properties for the xsd file the Custom Tool is MSDataSetGenerator. That is the likely culprit. So I found xsd2Code but it is old. XsdCodeGen in Code Generation in the .NET Framework Using XML Schema is newer but apparently I must build it to tyr it. I tried to set the Custom Tool for my XSD file to XsdCodeGen but then I got no Designer.cs file. But, that is a good thing. As I said, I don't want the Designer.cs file.

Does VS 2017 have a built-in Custom Tool corresponding to the MSDataSetGenerator tool that generates plain classes? I can't find that.



Sam Hobbs
SimpleSamples.Info

Continue reading...
 
Back
Top