Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i use the file that is generated by xsd.exe in windows 10 universal app

I am generating .cs files from .xsd files using xsd.exe. But when I am adding the files to windows 10 universal blank app, I was getting error as "missing an assembly reference" for System.SerializableAttribute() and System.ComponentModel.DesignerCategoryAttribute(‌​"‌​code"). I fixed this by @t.ouvre's trick. Then there were no errors in any of the particular line of the code but when i am building the code i am getting an error saying that " Cannot find type System.ComponentModel.MarshalByValueComponent in module System.dll" and it doesn't specify exactly where the error is. How can I use the file generated by xsd.exe in windows 10 universal app? What are all the things that I need to do with the file to use it for serialization and deserialization (using DataContractSerializer in UWP)

/// <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;
        }
    }
}
like image 381
Fresher Avatar asked Dec 22 '15 08:12

Fresher


People also ask

How do you use an XSD file?

An XSD file stores its contents as plain text in XML format, which means the files can be opened and viewed by any text editor and numerous other programs. However, if you want to edit an XSD file, you should use an XML editor, such as Microsoft XML Notepad, Bare Bones BBEdit, or SyncRO Soft oXygen XML Editor.

How do I open and edit XSD files?

To edit a fileSelect the Use XML editor to view and edit the underlying XML Schema file link on the Start View. The XML editor appears with the new file open. Copy the XML Schema sample code from Purchase order schema and paste it to replace the code that was added to the new XSD file by default.


1 Answers

You can fake missing classes (System.SerializableAttribute(),System.ComponentModel.DesignerCategoryAttribute), just add new files with theses classes definitions :

namespace System
{
    internal class SerializableAttribute : Attribute
    {
    }
}
namespace System.ComponentModel
{
    internal class DesignerCategoryAttribute : Attribute
    {
        public DesignerCategoryAttribute(string _) { }
    }
}

for serialization and deserialization, you have to use System.Runtime.Serialization.DataContractSerializer. For example :

DataContractSerializer serializer = new DataContractSerializer(typeof(request));
var r = new request { version = "test" };

using (MemoryStream ms = new MemoryStream())
{
    serializer.WriteObject(ms, r);
    ms.Seek(0, SeekOrigin.Begin);
    using (var sr = new StreamReader(ms))
    {
        string xmlContent = sr.ReadToEnd();
        Debug.WriteLine(xmlContent);
        ms.Seek(0, SeekOrigin.Begin);
        using (XmlReader reader = XmlReader.Create(sr))
        {
            var deserialized = serializer.ReadObject(reader) as request;
            if (deserialized != null && deserialized.version == r.version)
            {
                Debug.WriteLine("ok");
            }
        }
    }
}
like image 160
t.ouvre Avatar answered Sep 18 '22 03:09

t.ouvre