小编use*_*195的帖子

如何序列化XDocument对象?

我想序列化一个XDocument对象.我写了这段代码.

        XDocument signup_xml_file = new XDocument(
            new XDeclaration("1.0", "utf-8", "yes"),
            new XComment("signup_xml_file"),
            new XElement("Student",
                new XElement("univ_id", univ_id),
                new XElement("personal_id",personal_id),
                new XElement("user_name", user_name)));
        client.Connect(host_name, port);
        //connect to the server .
        bf.Serialize(client.GetStream(), signup_xml_file); // serialize the signup_xml_file
Run Code Online (Sandbox Code Playgroud)

尝试序列化时,我得到以下异常XDocument.是否有任何方法可以使XDocument类Serializable,还是有另一种方式发送我XDocument?

在Assembly'System.Xml.Linq,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'中键入'System.Xml.Linq.XDocument'未标记为可序列化.

.net c# xml serialization

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

.net ×1

c# ×1

serialization ×1

xml ×1