Google 网上论坛不再支持新的 Usenet 帖子或订阅项。历史内容仍可供查看。

Very strange "input string not in correct format" bug

已查看 129 次
跳至第一个未读帖子

Jen

未读,
2007年3月6日 14:46:032007/3/6
收件人
One user of my application is experiencing an exception "input string not in
correct format". But it makes no sense where it is occurring. It is
occurring when a string from a textbox ("172") is being convert to an Int16
(using Convert.ToInt16). How can that be? There are other text boxes that
are used in the identical fashion and they don't generate the exception.
All there are many other machines running my application that don't generate
the exception at all.

I have no idea what the problem could be and am looking for ideas.


Jon Skeet [C# MVP]

未读,
2007年3月6日 15:36:132007/3/6
收件人

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk...@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Jen

未读,
2007年3月6日 17:13:392007/3/6
收件人
I can post the relevant code snippets but I doubt I can reproduce the
problem. It's only occuring on one machine out of about a dozen tested.


"Jon Skeet [C# MVP]" <sk...@pobox.com> wrote in message
news:MPG.2057e11a6...@msnews.microsoft.com...

Jon Skeet [C# MVP]

未读,
2007年3月6日 17:31:222007/3/6
收件人
Jen <no...@nowhere.com> wrote:
> I can post the relevant code snippets but I doubt I can reproduce the
> problem. It's only occuring on one machine out of about a dozen tested.

Can you produce a short but complete program that fails on that single
machine? (A console app would be easiest.)

It does sound very odd...

Jen

未读,
2007年3月6日 20:42:472007/3/6
收件人
I'll see what I can do.

This almost smells like a culture-conversion type of problem. But
converting a string that only contains an integer number (and a small
integer number at that) to an int16? How can that fail? But I've been
Googling and it appears others have experienced it as well. Not sure about
an easy fix yet though.


"Jon Skeet [C# MVP]" <sk...@pobox.com> wrote in message

news:MPG.2057fc12c...@msnews.microsoft.com...

mpet...@gmail.com

未读,
2007年3月6日 21:05:002007/3/6
收件人
On Mar 6, 2:13 pm, "Jen" <n...@nowhere.com> wrote:
> I can post the relevant code snippets but I doubt I can reproduce the
> problem. It's only occuring on one machine out of about a dozen tested.

This sounds similar to a problem I saw a few months ago:

"Convert.ToInt32("0") throws an exception, some systems"
http://groups.google.com/group/microsoft.public.dotnet.framework/browse_frm/thread/1e2a5a340425a67b/9eb8e300c7c60821

I filed a bug with Microsoft; they're not able to reproduce it. You
might want to post some details in that bug report:

https://connect.microsoft.com/feedback/viewfeedback.aspx?FeedbackID=253265&wa=wsignin1.0&siteid=210

Michael

Jen

未读,
2007年3月6日 21:29:502007/3/6
收件人
Yep, it sounds just like my problem. I'm using .NET 2.0 as well.

<mpet...@gmail.com> wrote in message
news:1173233099....@v33g2000cwv.googlegroups.com...

bob

未读,
2007年3月7日 04:00:472007/3/7
收件人
Hi Jen,
This is based on nothing but intuition and witchcraft.
Can you check the culture info of the thread just prior to the offending
instruction?
regards
Bob

"Jen" <no...@nowhere.com> wrote in message
news:%233ZUVgC...@TK2MSFTNGP06.phx.gbl...

Laura T.

未读,
2007年3月7日 07:09:562007/3/7
收件人
What diffrences have the machines that generate exception?
Framework version, hot fixes, OS fixes, UI language/culture etc.?
I tried to reproduce the exception by setting the thread culture to all
possibile cultures I have (158) but did not get any exception from
Convert.ToInt16("172").
The only thing I cannot test that could have something to do with cultures
are the UI cultures but, I'd rather check first what are the differences.


"Jen" <no...@nowhere.com> ha scritto nel messaggio
news:%233ZUVgC...@TK2MSFTNGP06.phx.gbl...

Jen

未读,
2007年3月7日 08:20:392007/3/7
收件人
I can't really do a detailed analysis of the differences because the
offending machine is not accessible to me at the moment.

What the code is doing is it's taking a string from a TextBox that is part
of a User Control and converting it to a short. The exception's trace looks
something like this:

System.Number.StringToNumber()
System.Number.ParseInt32()
System.Number.Int16.Parse()
Util.IPAddressBox.get_Octet3() <-- this is an Int16 property in my user
control

I'm not sure why the call to ParseInt32 is there but I guess that's the way
it works. I've also seen the exception happen with textboxes that convert
right to Int32 instead of Int16. They are also accessed through a property
of a user control.


I am having the guy that owns the machine try the "set locale to something
else then back again to English (US)" trick that someone mentioned to see if
that fixes it. If it does not I'll pursue additional debugging.


"Laura T." <L...@NOWHERE.COM> wrote in message
news:eKdCTEL...@TK2MSFTNGP06.phx.gbl...

Jen

未读,
2007年3月7日 15:01:572007/3/7
收件人
It is very strange, that's for sure. Like in the example trace I posted
notice it was the 3rd octet of the IP address that threw the exception.
There were two octets before that that worked fine! Of course the numbers
in the textboxes are all different but all of them had valid small integers.

"Laura T." <L...@NOWHERE.COM> wrote in message

news:ekmChRMY...@TK2MSFTNGP03.phx.gbl...
> Yes, internally ToXX use parse to get the number.
> Just for curiosity I attach a .txt file here containing the code for the
> convert path that can raise the format exception.
> Reading it, it seems that only bad input data could trigger the exception,
> but...


>
>
> "Jen" <no...@nowhere.com> ha scritto nel messaggio

> news:ucjHptLY...@TK2MSFTNGP03.phx.gbl...

Jen

未读,
2007年3月14日 17:07:492007/3/14
收件人
Well, the trick of changing locale to something else and then back again did
fix the problem. I hope Microsoft can eventually find and fix this! It
will be interesting to see how many users of our app. have this problem once
the app. is released. At least we have an easy "fix" now to tell them.


"Jen" <no...@nowhere.com> wrote in message

news:ucjHptLY...@TK2MSFTNGP03.phx.gbl...

mpet...@gmail.com

未读,
2007年3月20日 13:52:272007/3/20
收件人
On Mar 14, 1:07 pm, "Jen" <n...@nowhere.com> wrote:
> Well, the trick of changing locale to something else and then back again did
> fix the problem. I hope Microsoft can eventually find and fix this! It
> will be interesting to see how many users of our app. have this problem once
> the app. is released. At least we have an easy "fix" now to tell them.

FWIW, I have another machine exhibiting this problem, and I've been
emailing back and forth with the class library team about it. They're
trying to debug it when neither I nor MS has physical access to the
machine. Not easy.

Michael

mpet...@gmail.com

未读,
2007年3月22日 15:17:572007/3/22
收件人

For reference, here's what we found. The affected machine had bad
data for the registry value [HKEY_CURRENT_USER\Control Panel
\International\sPositiveSign]. Normally, this value is an empty
REG_SZ (null-terminated string). In this case, the string was missing
its terminator. This confused the API function GetLocaleInfoW(),
causing it to think that '0' (ASCII number zero) was the positive sign
for the current locale (it should normally be '+'). This caused all
kinds of havoc.

You can verify this for yourself with regedit.exe: open that reg value
by right-clicking on the value and selecting 'Modify Binary Data'.
You should see two dots on the right (representing the null
terminator). If you see no dots, you're affected. Fix it by adding a
terminator (four zeros).

You can also check the value of
CultureInfo.CurrentCulture.NumberFormat.PositiveSign; it should be
'+'.

It's a bug in the Windows localization API, not the class libs. The
reg value needs to be checked for a terminator. They're looking at it.

Michael

0 个新帖子