2

"Input string was not in a correct format" - probably the most duplicate question here on Stack Overflow.

Having a Windows Forms application that is installed on serveral 10,000 PCs worldwide, I never saw this error until yesterday.

One single user recently reported the "Input string was not in a correct format" error. He is running Windows 7 and .NET 4.

What confuses me is the stack trace:

at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)    
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)    
at System.ComponentModel.Int32Converter.FromString(String value, NumberFormatInfo formatInfo)    
at System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)

This is the whole stack trace.

I.e. the exception seems to not originate in any of my own code.

My question:

Can anyone explain a possible program flow of my code that causes the above stack trace? (which does not show any of my code).

I'm still really confused how this might be possible at all.

Additional question:

Any idea about a possible reason for this error? Or how to get the real root cause for the error?

I can think of remote debugging but it seems like an overkill to me.

Update 1:

The user has a German culture ("de-DE") just like most of our customers and just like I have, too.

Community
  • 1
  • 1
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
  • 3
    It is difficult to help without knowing what the actual string is, that being said, I think that a good place to start looking is to ensure that your code can handle the various numerical representations across cultures. Notice that `1,000.6` (One thousand point 6) can also be written as `1.000,6` in some European cultures. – npinti Dec 28 '15 at 07:09
  • Thanks, @npinti. I cannot draw the line between the error and my code, since there seems to be only system code involved, but not my own code?!? – Uwe Keim Dec 28 '15 at 07:12
  • 1
    Yes but it might be that the system code is failing due to something which *your* code is passing through. I'd recommend patching the system to include some logging information or else remote debugging it to see what string is causing the problem. – npinti Dec 28 '15 at 07:14
  • So the displayed stack trace is wrong in your opinion, @npinti? Otherwise, if my code is passing through, it should appear in the stack trace?!? – Uwe Keim Dec 28 '15 at 07:21
  • 1
    No it is not wrong, but it might not be showing the complete picture. – npinti Dec 28 '15 at 07:24
  • 1
    I agree with @npinti, the best place to start is to compare you pc regional settings with the user's regional settings. Chances are you'll find the decimal representation is different. A quick/temp fix will be to change the user's regional settings to be like yours but the good fix is of course changing your code to handle all numerical representations. – Bayeni Dec 28 '15 at 08:24
  • 1
    do you use some controls that avail user input and return number? or possibly you pass it string? – Grundy Dec 28 '15 at 08:56
  • 1
    I would say that obviously that stack is not complete, even assuming an aggressive JIT inlining. I guess you already know it's a culture issue but to say _where_ in your code is absolutely a blind guess. Do you use TypeConverter somewhere? Also in configuration? Also asking your user for *exact* repro steps may help you to narrow your code base (even if you can't reproduce that error). – Adriano Repetti Dec 28 '15 at 09:15
  • 1
    CultureInfo settings can change between Windows versions, maybe even with updates. – leppie Dec 28 '15 at 09:45
  • Thanks, @leppie. My error handling records the culture at the time of the error. It was `de-DE`. – Uwe Keim Dec 28 '15 at 10:21
  • 1
    @UweKeim: No, I meant the actual values it has. For example, they 'fixed' floating-point formatting/parsing for en-ZA going from Win 7 to Win 8. Not sure if they have updated it for Win 7 yet. But I suspect something similar in your situation. – leppie Dec 28 '15 at 10:23

1 Answers1

1

Can anyone explain a possible program flow of my code that causes the above stack trace? (which does not show any of my code). Any idea about a possible reason for this error? Or how to get the real root cause for the error?

We need to see your code to tell what's wrong with it.

One possible explanation why your code does not come up on the stack is that the library code is running on a separate thread (or delegate?). Another reason could be, say, if you set an input validation mask on a control while constructing it, then when the control validates, potentially on some user input event, none of your code will be part of the stack trace. There are lot of reasons why the stack trace does not show any of your calls. A generic way of expressing that would be when your code passes data to library code and the library acts on it based on some completely separate event (like user input, timer, etc)

The way I would proceed is by looking for things like validation masks, etc done on controls. Also check if any number parsing type thing is happening on some delegate. Focus on controls in which users can type in data

Also, is it release build or debug build? Is it possible that the calls in the stack-trace are after optimization?

You can also add some variable information into your exception dumps. Check this post: How to get a dump of all local variables?

Community
  • 1
  • 1
Vikhram
  • 4,294
  • 1
  • 20
  • 32