This is because your second parameter sets the base to 2, and 2 is not a valid binary digit.
From MSDN
The call public static uint ToUInt32(string value, int fromBase)will call FormatExceptionwhen it valuecontains a character that is not a valid digit in the base specified fromBase. An exception message indicates that there are no digits to convert if the first character in the value is invalid; otherwise, the message indicates that the value contains invalid trailing characters.
source
share