Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.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# 读取XML属性时参数超出范围异常_C#_Xml - Fatal编程技术网

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

C# 读取XML属性时参数超出范围异常,c#,xml,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"?> &l

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

  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" />

使用LinqToXml怎么样

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

我应该怎样才能知道它在Donator属性中是“True”还是“False”?@user2678408再次查看代码。它返回一个布尔变量。
if(Donator==True){……}
@user2678408感谢您的解释性评论“仍然有错误”。你得到了什么错误?异常显示了什么?顺便说一句:我在发布之前测试了它。因此它确实有效…很抱歉我是一个noob:)#ArgumentOutOfRangeException:指定的参数超出了有效范围values@user2678408正如我说的“它有效”。除非你展示一下你是如何使用它的,否则我什么都不能说。顺便说一句:在我的帖子中没有代码可以获取
ArgumentOutOfRangeException
。你可能在别的地方得到它。
bool donator = (bool)XDocument.Load("GemsCraftConfig.gc") 
                              .Root.Attribute("Donator");