The code is compiled in VS2008 targeting .NET3.5. This is not reproducible on my system. I suspect some sort of localization setting is at play but I don’t know much about that.
All other valid numbers seem to work fine. The bug is illustrated with this code (which causes the same exception but is not the production code):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string str = "";
do
{
str = Console.ReadLine();
Console.WriteLine("\t\"{0}\"", Convert.ToDouble(str));
}
while (str != null);
}
}
}
At the command line, input of “0” crashes the app on at least one system I have encountered.
Stack trace from user’s PC:
System.FormatException: Input string was not in a correct format.
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)
at System.Double.Parse(String s, NumberStyles style, NumberFormatInfo info)
at System.Convert.ToDouble(String value)
I remember this problem from a question a while back. The Parse() methods are affected by the user overrides in the Control Panel + Region and Language applet. IIRC, it is especially sensitive to the “Negative sign symbol” setting. Ask your user to correct the settings there.
The reference question is here.