Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将字符串转换为Base64以在Xml.Serializer中使用_C#_Xml Serialization_Base64 - Fatal编程技术网

C# 将字符串转换为Base64以在Xml.Serializer中使用

C# 将字符串转换为Base64以在Xml.Serializer中使用,c#,xml-serialization,base64,C#,Xml Serialization,Base64,我正在尝试序列化一些XML数据,我正在通过套接字将其转换为一些可用的对象,起初我在接收0x10字符时遇到了问题,这些字符在1.0中显式无效,并且由于.NET不支持1.1,所以我被指示需要将我的特定字符串编码为Base64 这就是我对XML字符串的类所做的 [XmlRoot] public class message { [XmlElement] public string type { get; set; } [XmlElement] public str

我正在尝试序列化一些XML数据,我正在通过套接字将其转换为一些可用的对象,起初我在接收0x10字符时遇到了问题,这些字符在1.0中显式无效,并且由于.NET不支持1.1,所以我被指示需要将我的特定字符串编码为Base64

这就是我对XML字符串的类所做的

    [XmlRoot]
public class message
{
    [XmlElement]
    public string type { get; set; }
    [XmlElement]
    public string user { get; set; }
    [XmlElement]
    public string cmd { get; set; }
    [XmlElement]
    public string host { get; set; }
    [XmlElement]
    public byte[] msg { get; set; }

    public string GetCommand()
    {
        return System.Text.Encoding.UTF8.GetString(msg);
    }
}
我在这里读到:我可以将属性设置为byte[],它将自动编码为Base64,这就是我所做的。然后,我添加了一个方法来检索这个Base64,它是一个人类可读的字符串,我可以使用它,希望通过序列化来回避这个问题

但是,我在尝试序列化xml字符串时遇到了一个错误((0x10)是有问题的字符所在的位置,但它们不会显示在本文中):

XML字符串

<?xml version=\"1.0\"?><message><type>SERVER</type><user>TestDeleteOrKillMe</user>
<cmd>PRIVATE_MSG</cmd><host>65.255.81.81</host><msg>57(0x10)(0x10)</msg></message>
因此,从本质上说,这种方法让我得到了相同的回答,我很难理解为什么,有人能给我指一个演示代码或是关于为什么会发生这种情况的信息吗

 {"'', hexadecimal value 0x10, is an invalid character. Line 1, position 135."}