开发者

C# xml serializer - Unable to generate a temporary class

I am trying to serialize an xml to a class with the following way:

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 class PSW5 is generated automatically by xsd.exe using an PSW5.xsd file given to me. I have 开发者_开发技巧done the same for other classes and it works. Now i get the following error (during 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 for other classes the same way. I would appreciate any suggestions. Thanks inadvance, Giorgos


There seems to be other related topics on SO. Apparently you can resolve it by manually editing the output file.


Look at the xsd and the class - one of them will define a TAX_INF object, the other will define a TAX_INF[] array or collection.

The issue you are seeing is that the serializer can't translate from a single object to a collection.

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


It looks like you are loading from an XML file which defines a single element member (which is a PSW5ns.TAX_INF) of the same name as an array member of your class (which is a PSW5ns.TAX_INF[] array).
Are you sure you serialized that particular state of the class to the XML document you're loading from? If you changed the class and attempt to load an old state which doesn't match the current schema, you may get errors such as these.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜