[英]the string 'false' is not a valid boolean value
I am reading a value that is being written as a string using XmlWriter. 我正在读取使用XmlWriter以字符串形式写入的值。 Then it is being read by XmlReader and converted to a boolean. 然后,它由XmlReader读取并转换为布尔值。 Finally, the same XmlWriter method is called to write out to a separate Xml file. 最后,调用相同的XmlWriter方法以写出到单独的Xml文件。 But when I try to write the element the second time I am getting a failed unit test that says: 但是,当我第二次尝试编写元素时,单元测试失败,提示:
Result Message:
Test method threw exception:
System.FormatException: The string 'False' is not a valid Boolean value.
I am writing the element with 我在写元素
writer.WriteStartElement("variableNameIsRelative");
writer.WriteCData(p.VariableNameIsRelative.ToString());
writer.WriteEndElement();
then reading with 然后用
param.VariableNameIsRelative = XmlConvert.ToBoolean(reader.ReadElementContentAsString());
and again using the same writer as before just outputting to a different file (this is where it breaks.) 并再次使用与以前相同的编写器,只是将其输出到另一个文件(这是断点)。
writer.WriteStartElement("variableNameIsRelative");
writer.WriteCData(p.VariableNameIsRelative.ToString());
writer.WriteEndElement();
So my question is..Is there anything different I have to do to convert "false" to a valid boolean value in XmlSerialization vs what I am currently doing here? 所以我的问题是..与我目前在这里做的事情相比,我是否需要做其他什么工作才能将“ false”转换为XmlSerialization中的有效布尔值? And if so, what might that be? 如果是这样,那可能是什么?
XmlConvert.ToBoolean
only accept false
in lower case string. XmlConvert.ToBoolean
仅在小写字符串中接受false
。 You are probably confusing it with Convert.ToBoolean
您可能将其与Convert.ToBoolean
混淆了
XmlConvert.ToBoolean Method (String) XmlConvert.ToBoolean方法(字符串)
Valid strings are "1" or "true" for true and "0" or "false" for false. 有效字符串为“ 1”或“ true”表示“ true”,为“ 0”或“ false”表示“ false”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.