問題描述
我使用 xsd.exe 工具從我的 xsd 文件創建了一個類后收到此錯誤.所以我在網上搜索并找到了解決方案.這是鏈接:http://satov.blogspot.com/2006/12/xsdexe-generated-classes-causing.html
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
問題是這會使代碼運行,但反序列化的數據似乎已損壞.我按照網站的建議做了,最后第二個數組維度總是空的(見網站的評論,有人也有這個問題).問題是,我現在該如何解決這個問題?是否有其他工具可以創建 xsd 文件?我嘗試了 Xsd2Code,但沒有成功.
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.
謝謝:-)
推薦答案
需要更改序列化類中成員變量的類型.例如,如果它引發如下錯誤:
You need to change the type of a member variable in the serialized class. For example if its raising an error like:
無法生成臨時類(結果=1).錯誤 CS0030:無法將類型Data[]"轉換為Data".
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
將 Data[][]
替換為 Data[]
- 將 Data 的類型從 2D 數組更改為 1D 數組.它會解決你的問題.:)
Replace Data[][]
with Data[]
- Change the type of Data from a 2D array to a 1D array. It would solve your problem. :)
這篇關于無法生成臨時類(結果=1).錯誤 CS0030:無法將類型“Type[]"轉換為“Type"?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!