Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

System.FormatException occurs when attempting to convert a numeric string to a numeric data type


View products that this article applies to.

Source: Microsoft Support

↑ Back to the top


Rapid publishing

RAPID PUBLISHING ARTICLES PROVIDE INFORMATION DIRECTLY FROM WITHIN THE MICROSOFT SUPPORT ORGANIZATION. THE INFORMATION CONTAINED HEREIN IS CREATED IN RESPONSE TO EMERGING OR UNIQUE TOPICS, OR IS INTENDED SUPPLEMENT OTHER KNOWLEDGE BASE INFORMATION.

↑ Back to the top


Action



You attempt to cast a numeric string to a numeric data type, using code similar to the following.

Dim strInput As String = "10"
Dim intResult As Integer = 0
Try
intResult = Convert.ToInt16(strInput)
Catch ex As Exception
MessageBox.Show("Error: " & ex.Message)
End Try

↑ Back to the top


Result



You receive a System.FormatException with the following error and stack trace.

"Input string was not in a correct format."

A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
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.Int16.Parse(String s, NumberStyles style, NumberFormatInfo info)
at System.Convert.ToInt16(String value)
at TypeConversionTest.Form1.cmdConvert_Click(Object sender, EventArgs e) in C:\Source\TypeConversionTest\TypeConversionTest\Form1.vb:line 7

↑ Back to the top


Cause



There is an incorrect value in the following value in the Windows registry:

HKEY_CURRENT_USER\Control Panel\International\sPositiveSign

This value should be empty for most English Language settings. Note that when this error occurs, the value may appear empty visually, but may contain a space or unprintable character.

↑ Back to the top


Resolution



While it is possible to directly edit the value for the problem key, the preferred method is to change the Regional Settings to a different Region/Language and then reset it to the desired setting:

1. Open the Regional and Language Options applet from the Control Panel.
2. Note the Current Format.
3. Change the Current Format to English (Australian)
4. Click Apply.
5. Change the Current Format to the noted format, eg, English (American).
6. Click Apply and then click OK.

This action resets every value under the HKEY_CURRENT_USER\Control Panel\International registry key.

↑ Back to the top


Moreinformation




↑ Back to the top


Disclaimer

MICROSOFT CORPORATION AND/OR ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY, RELIABILITY, OR ACCURACY OF THE INFORMATION AND RELATED GRAPHICS CONTAINED HEREIN. ALL SUCH INFORMATION AND RELATED GRAPHICS ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT AND/OR ITS RESPECTIVE SUPPLIERS HEREBY DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THIS INFORMATION AND RELATED GRAPHICS, INCLUDING ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, WORKMANLIKE EFFORT, TITLE AND NON-INFRINGEMENT. YOU SPECIFICALLY AGREE THAT IN NO EVENT SHALL MICROSOFT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, PUNITIVE, INCIDENTAL, SPECIAL, CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF USE, DATA OR PROFITS, ARISING OUT OF OR IN ANY WAY CONNECTED WITH THE USE OF OR INABILITY TO USE THE INFORMATION AND RELATED GRAPHICS CONTAINED HEREIN, WHETHER BASED ON CONTRACT, TORT, NEGLIGENCE, STRICT LIABILITY OR OTHERWISE, EVEN IF MICROSOFT OR ANY OF ITS SUPPLIERS HAS BEEN ADVISED OF THE POSSIBILITY OF DAMAGES.

↑ Back to the top


Keywords: kbnomt, kbrapidpub, KB942460

↑ Back to the top

Article Info
Article ID : 942460
Revision : 1
Created on : 9/11/2007
Published on : 9/11/2007
Exists online : False
Views : 266