【发布时间】:2015-12-22 08:28:52
【问题描述】:
我正在使用 xsd.exe 从 .xsd 文件生成 .cs 文件。但是,当我将文件添加到 Windows 10 通用空白应用程序时,我收到错误,因为 System.SerializableAttribute() 和 System.ComponentModel.DesignerCategoryAttribute("code") 的“缺少程序集引用”。我通过@t.ouvre 的技巧解决了这个问题。然后在代码的任何特定行中都没有错误,但是当我构建代码时,我收到一条错误消息,提示“在模块 System.dll 中找不到类型 System.ComponentModel.MarshalByValueComponent”并且它没有准确指定错误在哪里。如何在 windows 10 通用应用程序中使用 xsd.exe 生成的文件?我需要对文件执行哪些操作才能将其用于序列化和反序列化(在 UWP 中使用 DataContractSerializer)
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.81.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
public partial class request
{
private usertype userField;
private string versionField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public usertype user
{
get
{
return this.userField;
}
set
{
this.userField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string version
{
get
{
return this.versionField;
}
set
{
this.versionField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.81.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class usertype
{
private string emailField;
private string passwordField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string email
{
get
{
return this.emailField;
}
set
{
this.emailField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string password
{
get
{
return this.passwordField;
}
set
{
this.passwordField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.81.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
public partial class NewDataSet
{
private request[] itemsField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("request")]
public request[] Items
{
get
{
return this.itemsField;
}
set
{
this.itemsField = value;
}
}
}
【问题讨论】:
-
你能发布一个生成的文件吗?
-
System.SerializableAttribute(),System.ComponentModel.DesignerCategoryAttribute("code") 显示错误为“不存在,缺少程序集引用”。它不会在控制台应用程序中显示任何错误。
-
可以手动删除非编译属性吗? (System.SerializableAttribute(),System.ComponentModel.DesignerCategoryAttribute("code"))
-
我有很多文件。手动编辑需要很长时间。但如果没有其他选择,我将不得不这样做。手动删除后,是否需要添加 DataContract 才能使其在序列化过程中正常工作?
-
抱歉耽搁了,请看我的回复;)
标签: c# serialization win-universal-app xsd.exe windows-10-universal