TryParse Throwing An Exception Using ClickOnce

N

nautonnier

Hello All,

I'm validating a textbox to make sure it contains only a whole number
so I'm using Int32.TryParse. It works fine when I test it on a local
winform app. However, when I transfer the code to my project that's
using ClickOnce, it throws an error.

Here's the code that's identical in both projects:
int parseResult;
if (Int32.TryParse(txtNumberTest.Text, out parseResult))
{
if (parseResult <= 0)
{
isValid = false;
errorMessage += "Textbox must be a number error message\n";
}
}

The error is follows:
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)
at myClickOnceApp.frmMain.checkForm()
at myClickOnceApp.frmMain.btnSave_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)

Any ideas would be appreciated.
 
M

Mattias Sjögren

I'm validating a textbox to make sure it contains only a whole number
so I'm using Int32.TryParse. It works fine when I test it on a local
winform app. However, when I transfer the code to my project that's
using ClickOnce, it throws an error.

What makes you think it's the call to TryParse that throws the
exception, when TryParse is not in the stack trace you posted?


Mattias
 
A

andy

Hello All,

I'm validating a textbox to make sure it contains only a whole number
so I'm using Int32.TryParse. It works fine when I test it on a local
winform app. However, when I transfer the code to my project that's
using ClickOnce, it throws an error.

Here's the code that's identical in both projects:
int parseResult;
if (Int32.TryParse(txtNumberTest.Text, out parseResult))
{
if (parseResult <= 0)
{
isValid = false;
errorMessage += "Textbox must be a number error message\n";
}

}

The error is follows:
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)
at myClickOnceApp.frmMain.checkForm()
at myClickOnceApp.frmMain.btnSave_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)

Any ideas would be appreciated.

Maybe it's a culture problem.
I use.

public static bool IsNumeric(string stringToTest)
{
double newVal;
return double.TryParse(stringToTest, NumberStyles.Any,
NumberFormatInfo.InvariantInfo, out newVal);
}
 
J

James Swindell

nautonnier,

From the supplied stack-trace, the problem is stemming from an invalid
Double conversion call somewhere within frmMain.checkForm.

James
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top