Unable to generate a temporary class (result=1). e

2019-01-17 02:26发布

I get this error after I created a class from my xsd file using the xsd.exe tool. So I searched the net and found a solution. Here is the link: http://satov.blogspot.com/2006/12/xsdexe-generated-classes-causing.html

Problem is that this makes the code run, but somehow the deserialized data seems corrupt. I did what the site suggests and in the end the 2nd array dimension is always empty (see the comments of the site, somebody also had this problem). Question is, how do I solve this issue now? Is there another tool to create the xsd file? I tried Xsd2Code, without success.

Thanks :-)

7条回答
看我几分像从前
2楼-- · 2019-01-17 02:56

You need to change the type of a member variable in the serialized class. For example if its raising an error like:

Unable to generate a temporary class (result=1). error CS0030: Cannot convert type 'Data[]' to 'Data'.

I ran a search on the Data type name in the generated file, and I found this:

[System.Xml.Serialization.XmlArrayItemAttribute("Data", typeof(Data), IsNullable=false)]
public Data[][] Row

Replace Data[][] with Data[] - Change the type of Data from a 2D array to a 1D array. It would solve your problem. :)

查看更多
别忘想泡老子
3楼-- · 2019-01-17 02:59

For me it helps to patch the XML used to generate the code. It happens when:

<Names>
    <Name></Name>
    <Name></Name>
</Names>

then this is optimized by xsd to double array name entry

What I did is:

<Names>
    <Dummy></Dummy>
    <Name></Name>
    <Name></Name>
</Names>

the xsd doesn't optimize it but leaves the single array name

查看更多
forever°为你锁心
4楼-- · 2019-01-17 03:07

If its in VB.net then you got to search for ()() in your Reference.vb and replace with()

查看更多
对你真心纯属浪费
5楼-- · 2019-01-17 03:13

I got this error.In your solution there is reference.cs file in that file you need to search "[][]" and then there will be two results in it..

After you need to remove one "[]" from "[][]" from both places..

It works for me..

Thanks..

查看更多
ら.Afraid
6楼-- · 2019-01-17 03:14

For my case, the issue cases due to an invalid declaration for XmlArrayItem property attribute.

From

[XmlArrayItem("MyArray", typeof(string))]
public List<ClassName> Items{ get; set; }

I changed with appropriate type: from string to ClassName

[XmlArrayItem("MyArray", typeof(ClassName))]
public List<ClassName> Items{ get; set; }

Hope this helps!

查看更多
欢心
7楼-- · 2019-01-17 03:17

Had the same problem, but Xsd2Code didn't integrate with VS2012. So instead I went to my xsd.exe generated .cs file and did:

Find [][] Replace []

which worked.

查看更多
登录 后发表回答