Share via


Format exception occuring in only one system using Convert.ToInt32

Question

Wednesday, September 29, 2010 9:08 AM

Below exception is thrown when converting a "0" to int using Convert.Toint32.

This exception is occuring in only one system.

Type : System.FormatException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
  Message : Input string was not in a correct format.
  Source : mscorlib
  Help link :
  Data : System.Collections.ListDictionaryInternal
  TargetSite : Void StringToNumber(System.String, System.Globalization.NumberStyles, NumberBuffer ByRef, System.Globalization.NumberFormatInfo, Boolean)
  Stack Trace :    at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
     at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
     at System.Convert.ToInt32(String value)

Can some one suggest why this is happening in a particular system 

 

 

All replies (1)

Thursday, October 7, 2010 4:03 PM

If you are sure that the string is identical on this system, you may want to try using Int32.Parse and specify a specific culture, just in case that system has an unusual culture setting:

 

   int value = int.Parse("0", CultureInfo.InvariantCulture); // Force invariant culture for the conversion

Reed Copsey, Jr. - http://reedcopsey.com