Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.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# 序列化DictionaryEntry[]属性时发生XML错误_C#_Xml_Arrays_Xml Serialization - Fatal编程技术网

C# 序列化DictionaryEntry[]属性时发生XML错误

C# 序列化DictionaryEntry[]属性时发生XML错误,c#,xml,arrays,xml-serialization,C#,Xml,Arrays,Xml Serialization,我得到一个异常消息:“XML文档中有一个错误” 代码: private readonly SortedList\u属性; [XmlArray(“属性”)] [XmlArrayItem(“AttributesLine”,Type=typeof(DictionaryEntry))] 公共字典入口[]\u x\u属性 { 得到 { DictionaryEntry[]ret=新DictionaryEntry[\u attributes.Count]; int i=0; foreach(KeyValu

我得到一个异常消息:“XML文档中有一个错误”

代码:

private readonly SortedList\u属性;
[XmlArray(“属性”)]
[XmlArrayItem(“AttributesLine”,Type=typeof(DictionaryEntry))]
公共字典入口[]\u x\u属性
{ 
得到
{ 
DictionaryEntry[]ret=新DictionaryEntry[\u attributes.Count];
int i=0;
foreach(KeyValuePair填充行输入_属性)
{

object value=stuffLine.value;//我假设您使用的是XMLSerializer,它无法处理通用字典对象。我看到自己在使用字典时抛出了该错误。您需要选择其他可以处理它们的序列化程序之一


请改用DataContractSerializer

谢谢,但我很难替换序列化程序。此外,它目前使用单浮点值。
        private readonly SortedList<string, object> _attributes;

        [XmlArray("Attributes")] 
        [XmlArrayItem("AttributesLine", Type=typeof(DictionaryEntry))] 
        public DictionaryEntry[] _x_Attributes 
        { 
            get 
            { 
                DictionaryEntry[] ret = new DictionaryEntry[_attributes.Count]; 
                int i=0;
                foreach (KeyValuePair<string, object> stuffLine in _attributes)
                {
                    object value = stuffLine.Value;     // <--- float[]         
                    ret[i++] = new DictionaryEntry {Key = stuffLine.Key, Value = value};                
                }
                return ret; 
            }
            set
            {
                _attributes.Clear();
                foreach (DictionaryEntry entry in value)
                {
                    _attributes.Add((string) entry.Key, entry.Value);
                }
            }
        }