Author Topic: bug in my winusb_cs code for some non-US users  (Read 12250 times)

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
bug in my winusb_cs code for some non-US users
« on: December 09, 2022, 11:44:53 am »
A user reported this bug in my winusb_cs code for some non-US users:

The Windows version check fails with "FormatException: input was not in correct format" for users where the decimal separator is a comma, e.g. in some European countries. The exception is thrown around line 742 of frmMain.cs:

var windowsVersion = Convert.ToDecimal(completeWindowsVersion.Substring(0, 3));

And the fix is:

var windowsVersion = Convert.ToDecimal(completeWindowsVersion.Substring(0, 3), CultureInfo.InvariantCulture);

It's also needed to add "using System.Globalization;" at the top of the file.

That's because "completeWindowsVersion" always uses a point as separator (e.g. "6.3.9600.0"), but Convert.ToDecimal() uses by default the local decimal separator for conversion.


The code is here:

http://janaxelson.com/winusb.htm