C # xml serializer - Cannot create temporary class

I am trying to serialize xml for a class like this:

XmlSerializer ser = new XmlSerializer(typeof(PSW5ns.PSW5));
StringReader stringReader;
stringReader = new StringReader(response_xml);
XmlTextReader xmlReader;
xmlReader = new XmlTextReader(stringReader);
PSW5ns.PSW5 obj;
obj = (PSW5ns.PSW5)ser.Deserialize(xmlReader);
xmlReader.Close();
stringReader.Close();

      

the PSW5 class is generated automatically by xsd.exe using the PSW5.xsd file provided to me. I have done the same for other classes and it works. Now I am getting the following error (at runtime):

{"Unable to generate a temporary class (result=1).\r\nerror CS0030: 
Cannot convert type 'PSW5ns.TAX_INF[]' to 'PSW5ns.TAX_INF'\r\nerror CS0029: 
Cannot implicitly convert type 'PSW5ns.TAX_INF' to 'PSW5ns.TAX_INF[]'\r\n"}

      

I am confused because it works the same for other classes. Any suggestions would be appreciated. Thanks in advance, Yorgos

+2


a source to share


3 answers


There seems to be other related topics on SO. Obviously, you can resolve this by manually editing the output file.



+2


a source


Look at xsd and class - one will define an object TAX_INF

, the other will define an array or collection TAX_INF[]

.

The problem you are seeing is that the serializer cannot translate from one object to a collection.



To fix the problem, make sure the xsd and class match.

+1


a source


It looks like you are loading from an XML file that defines one member element (which is PSW5ns.TAX_INF

) with the same name as your class's array member (which is an array PSW5ns.TAX_INF[]

).
Are you sure you have serialized this particular class state in the XML document you are loading? If you change the class and try to load an old state that does not match the current schema, you might get errors like this.

0


a source







All Articles