473,378 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

TryParse Throwing An Exception Using ClickOnce

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(MouseEventAr gs 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.O nMessage(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)

Any ideas would be appreciated.

Apr 26 '07 #1
3 2756
>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

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Apr 26 '07 #2
On 26 Apr, 21:21, nautonnier <chu...@cleanrecords.comwrote:
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(MouseEventAr gs 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.O nMessage(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.W ndProc(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);
}

Apr 27 '07 #3
nautonnier,

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

James

"nautonnier" <ch****@cleanrecords.comwrote in message
news:11*********************@c18g2000prb.googlegro ups.com...
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(MouseEventAr gs 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.O nMessage(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)

Any ideas would be appreciated.

Apr 27 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Farooq Khan | last post by:
i'm writing a class library having following code snippet. i want this class to report an error (by throwing an Exception) to the application using this class library. the problem is that within...
40
by: Kevin Yu | last post by:
is it a bad programming design to throw exception in the try block then catch it??
9
by: Mark Rae | last post by:
Hi, Can anyone please tell me if there is any difference in throwing an exception with or without parentheses, e.g. try { /* code */
5
by: Greg Wilkerson | last post by:
Ok, Someone tell me what I'm doing wrong. The statement below is returning 527.0 in v, instead of the expected 215. Am I missing something? double v; if (Double.TryParse("0d7",...
1
by: John A Grandy | last post by:
Primitives like Int32 provide a Parse() method , and TryParse() method -- which is very useful. Enum provides a Parse() method, but not a TryParse() method. Other than wrapping the...
6
by: Marvin Barley | last post by:
I have a class that throws exceptions in new initializer, and a static array of objects of this type. When something is wrong in initialization, CGI program crashes miserably. Debugging shows...
1
by: usenet | last post by:
I wrote some sample code (see below) for nested exception throwing i.e. my catch blocks are throwing exceptions of their own (for simplicity I used standard exceptions). I am getting some...
0
by: Pieter | last post by:
Hi, When using clickOnce for a VB.NET 2.0 application it installs fine on every computer, except one (a new one...). Every is isstalled, Framework, Mdac, .... The error in the log file is:...
3
by: Peter Carlson | last post by:
Our app uses the following chain of urls: 1. yoursite.com/launch.php?room=00000271 - validates the roomid appends an appropriate server variable and encrypts and adds a hash and sends on to #2 ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.