C#xml反序列化

C#xml反序列化,c#,xml,deserialization,C#,Xml,Deserialization,我有一个叫做identity namespace Game.World.Entities { [XmlRoot("Identity")] public class Identity { public string Name { get; set; } public string Texture { get; set; } public string HeroType { get; set; } public

我有一个叫做
identity

namespace Game.World.Entities
{
    [XmlRoot("Identity")]
    public class Identity
    {
        public string Name { get; set; }
        public string Texture { get; set; }
        public string HeroType { get; set; }

        public Stats Stats { get; set; }
        public ActiveAbilitites ActiveAbilitites { get; set; }
        public PassiveAbilitites PassiveAbilitites { get; set; }
    }

    public class ActiveAbilitites
    {
        [XmlElement("AbilityId")]
        public List<int> ActiveAbilitiesId { get; set; }
    }

    public class PassiveAbilitites
    {
        [XmlElement("AbilityId")]
        public List<int> PassiveAbilitiesId { get; set; }
    }

    public class Stats
    {
        public int Health { get; set; }
        public int MagicDamage { get; set; }
        public int PhysicalDamage { get; set; }
        public int Defense { get; set; }
    }
}
namespace Game.World.Entities
{
[XmlRoot(“标识”)]
公共阶级身份
{
公共字符串名称{get;set;}
公共字符串纹理{get;set;}
公共字符串类型{get;set;}
公共统计数据{get;set;}
公共活动属性活动属性{get;set;}
公共被动属性被动属性{get;set;}
}
公共类活动属性
{
[XmlElement(“能力ID”)]
公共列表ActiveAbiliteId{get;set;}
}
公共类被动性
{
[XmlElement(“能力ID”)]
公共列表被动性ID{get;set;}
}
公共类统计
{
公共int运行状况{get;set;}
公共整数MagicDamage{get;set;}
公共int物理损坏{get;set;}
公共整数防御{get;set;}
}
}
我已将该类序列化为xml文档:

<?xml version="1.0" encoding="utf-8"?>
<Identity xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Name>foo</Name>
  <Texture>player</Texture>
  <HeroType>tracker</HeroType>
  <Stats>
    <Health>5</Health>
    <MagicDamage>5</MagicDamage>
    <PhysicalDamage>5</PhysicalDamage>
    <Defense>5</Defense>
  </Stats>
  <ActiveAbilitites>
    <AbilityId>1</AbilityId>
    <AbilityId>2</AbilityId>
    <AbilityId>3</AbilityId>
  </ActiveAbilitites>
  <PassiveAbilitites>
    <AbilityId>1</AbilityId>
    <AbilityId>2</AbilityId>
    <AbilityId>3</AbilityId>
  </PassiveAbilitites>
</Identity>

福
运动员
跟踪器
5.
5.
5.
5.
1.
2.
3.
1.
2.
3.
但是,当我尝试将xml反序列化为
标识
对象时,会出现错误

xml文档(2,2)中有错误…
不应出现System.InvalidOperationException。
在Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderList1.Read6_ArrayFidenty()上


这让我很困惑,因为xml来自seralization,所以我不知道为什么我不能反序列化它。我想我错过了某个地方的一个注释标记。在这方面的任何帮助都会令人惊讶。

这是我如何对代码进行反序列化的一个问题。我不知道我做了什么把它搞得这么糟,但我想这是因为我的字符串阅读器。我刚刚从中复制并粘贴了一些示例代码,现在可以正常工作。

您可以向我们展示用于bot序列化和反序列化的代码吗?结果是反序列化代码,如果从.xml文件中读取,则可以正常工作,但当我从字符串中反序列化xml时,出现了错误。当我使用字符串编辑时,我会更新此注释不知道我做了什么使反序列化程序如此混乱,但我现在使用的是字符串。变量读取器=新的StringReader(模板);var identity=(identity)序列化程序。反序列化(reader);请不要把答案放在问题里。我把它拿走了。