PC Review


Reply
Thread Tools Rate Thread

Convert::ToInt32 problem

 
 
Dave Farquharson
Guest
Posts: n/a
 
      4th Apr 2008
I am using Convert::ToInt32 to convert a string to an integer. On some small
number of machines this is causing a System.FormatException. After chucking
the problem at Google I found some promising info on a very strange registry
problem --

HKEY_CURRENT_USER | Control Panel | International | sPositiveSign

can become corrupted in such a way that certain strings can generate this
exception. For instance, if sPositiveSign is "0" then a ToInt32("0") will
throw. I can cause the symptoms my small set of machines see by forcing my
own to "0".

All weird, but well and good, except the machines in question do not have
anything unusual in sPositiveSign. Normally in the US this registry entry is
blank, and it is in fact blank on the machines in question.

So, anyone know of any other reason this could blow up? I log what the code
thinks is bad data and it is in fact ToInt32("0") that is dying for whatever
reason. This is .net 2.0.

Very odd.

-dave


 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      4th Apr 2008
Dave Farquharson <(E-Mail Removed)> wrote:

<snip>

> So, anyone know of any other reason this could blow up? I log what the code
> thinks is bad data and it is in fact ToInt32("0") that is dying for whatever
> reason. This is .net 2.0.
>
> Very odd.


Silly question, probably, but I guess you've thought of all the
sensible ones already: are you absolutely sure it's "0" and not "0 " or
" 0"?

Does a program which *just* converts "0" in the above manner fail in
the same way?

What about a call to
Convert.ToInt32("0", CultureInfo.InvariantCulture)?

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
 
Reply With Quote
 
Dave Farquharson
Guest
Posts: n/a
 
      4th Apr 2008
Hey Jon, thanks for the reply.

Hmm.

Well, I am sure of the "0" vs " 0" vs " 0" part, and I've distilled our huge
app down to a small set of things that do break (your "just converts"
question), but I have not tried the InvariantCulture thing. I will give that
a shot. Thanks!


"Jon Skeet [C# MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Dave Farquharson <(E-Mail Removed)> wrote:
>
> <snip>
>
>> So, anyone know of any other reason this could blow up? I log what the
>> code
>> thinks is bad data and it is in fact ToInt32("0") that is dying for
>> whatever
>> reason. This is .net 2.0.
>>
>> Very odd.

>
> Silly question, probably, but I guess you've thought of all the
> sensible ones already: are you absolutely sure it's "0" and not "0 " or
> " 0"?
>
> Does a program which *just* converts "0" in the above manner fail in
> the same way?
>
> What about a call to
> Convert.ToInt32("0", CultureInfo.InvariantCulture)?
>
> --
> Jon Skeet - <(E-Mail Removed)>
> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
> World class .NET training in the UK: http://iterativetraining.co.uk



 
Reply With Quote
 
Michael Petrotta
Guest
Posts: n/a
 
      9th May 2008
On Apr 3, 4:24 pm, "Dave Farquharson" <gamerfarquhar...@hotmail.com>
wrote:

> Well, I am sure of the "0" vs " 0" vs " 0" part, and I've distilled our huge
> app down to a small set of things that do break (your "just converts"
> question), but I have not tried the InvariantCulture thing. I will give that
> a shot. Thanks!


Dave, I hope this is not too late to be useful. Take a look at this
post for the resolution:
http://groups.google.com/group/micro...a5728efb29fe90

Summary: it's a bug, not in .NET, but in the Windows localization
libraries, triggered by possibly-corrupt registry entries. The
corruption is not easy to see, but it is easy to fix.

Michael
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
IsNumeric: Convert.ToInt32 vs. Convert.ToInt64 sck10 Microsoft ASP .NET 4 3rd Sep 2006 10:40 PM
Difference between Cint and Convert.ToInt32 ? =?Utf-8?B?UmljaA==?= Microsoft VB .NET 4 22nd Jul 2006 05:50 AM
Convert.ToInt32(char) omeraa@gmail.com Microsoft Dot NET Framework 1 17th Jan 2006 07:23 AM
(int) or convert.ToInt32 ? =?Utf-8?B?SmFyb2Q=?= Microsoft C# .NET 8 22nd Jun 2005 07:07 PM
Advantage between (int) and Convert.ToInt32? =?Utf-8?B?Y2hhcmxpZXdlc3Q=?= Microsoft C# .NET 1 16th Feb 2005 06:32 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:21 AM.