FormatException: could not find recognized digits

I get this exception:

The first random error like "System.FormatException" occurred in mscorlib.dll

In this line:

String value = "2";
uint? test = Convert.ToUInt32(value, 2);
+4
source share
1 answer

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.

+6
source

Source: https://habr.com/ru/post/1618373/


All Articles