Reputation: 12484
This is a .NET error:
Error Message: String was not recognized as a valid Boolean.
Error Source : mscorlib
This may be a bit cryptic-sounding but that's all I have to show. How to go about retracing what happened... I really need help on this, how can this come up if it didn't appear before, though the application was the same. thanks
Upvotes: 0
Views: 147
Reputation: 38456
This error occurs when using bool.Parse()
and the input into the method is not convertible to a boolean value of true/false.
For instance:
string testBool = "true";
bool validBool = bool.Parse(testBool);
// this passes fine
testBool = "asdf";
validBool = bool.Parse(testBool);
// Exception: String was not recognized as a valid Boolean.
If you're using .NET 4.0 or higher, you can use bool.TryParse()
instead; it will not throw the exception if it receives invalid input. Otherwise, wrap the statement in a try / catch
to consume it.
Upvotes: 8