Convert::ToInt32 problem

  • Thread starter Thread starter Dave Farquharson
  • Start date Start date
D

Dave Farquharson

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
 
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)?
 
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!
 
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/micr...145e0b/05a5728efb29fe90?#doc_05a5728efb29fe90

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
 
Back
Top