读取XML属性时参数超出范围异常

时间:2014-01-31 00:14:21

标签: c# xml

我收到以下错误(我有一个报告我的问题的自定义错误控制台

  7:09:17 PM > # ArgumentOutOfRangeException: Specified argument was out of the range of valid values. 
  7:09:17 PM > # Parameter name: i

当我尝试从XML文件GemsCraftConfig.gc

中读取以下“捐赠者”属性时,会出现这种情况
<?xml version="1.0" encoding="utf-8"?>
<GemsCraft Donator="True" />

这是我用来执行操作的代码......它在Visual Basic中运行良好,但当我通过在线转换器时它

   XmlTextReader Reader = new XmlTextReader("GemsCraftConfig.gc");
        string DonatorEnabled = Reader.GetAttribute(0);

            if (DonatorEnabled == "True")
            {
  //Code is cut off from here on

1 个答案:

答案 0 :(得分:1)

如何使用LinqToXml

bool donator = (bool)XDocument.Load("GemsCraftConfig.gc") 
                              .Root.Attribute("Donator");