Index was out of range?

I really hate to bother anyone with this seemingly simple question but it appears I am at the dead end.

I got this message this morning: Index was out of range. Must be .... Parameter name: startIndex.

There are three problem with it. Number one: I have almost debugged this massive application and it seems everything has been working for some time. Unless somehow the input stream's format changed which remains to be checked I do not know where to look.

Second, there is no pointer as to where in the source code it happens.

And thirdly, I checked and rechecked and I swear I do not have any variable of parameter named startIndex in the entire project.

On top of that this error message does not seem to impede the performance. First it appeared twice per run and now only once. It is suggestive of the input stream format change but still I am not certain. If I ignore it the whole app keeps working like nothing happened.

Any suggestions

thanks.




Answer this question

Index was out of range?

  • Jasbir

    ahmedilyas wrote:
    if you are using a lot of substrings then you are doing something incorrectly in that there maybe a better way of doing what you are doing than string parsing. I would suggest finding another solution/method but also making sure you check inputs before proceeding to do what you are doing (check to see if the character/string exists before performing an operation in it via the IndexOf() method, it will return -1 if the string specified was not found)

    Thank you, Ahmed. I am using indexOf() all the time. WIthout it the Substring operation loses any sense.

    What other method do you have in mind



  • Jan Kučera

    if you are using a lot of substrings then you are doing something incorrectly in that there maybe a better way of doing what you are doing than string parsing. I would suggest finding another solution/method but also making sure you check inputs before proceeding to do what you are doing (check to see if the character/string exists before performing an operation in it via the IndexOf() method, it will return -1 if the string specified was not found)

  • Dhaval Patel

    CommonGenius.com wrote:
    You say you are "getting this message", but there is no source code location. Where are you getting the message Is an exception being thrown Are you seeing it in the output window

    Hi and thank you for paying attention. I am not sure how to answer your questions, honestly. The environment is: VS2005, C#, Windows App. Debug. There is no exception thrown as far as I can see, because otherwise the execution would have broken down. The debug keeps running. A grey long form (window) appears and I can read this message. There is one (or two, I do not remember clearly) button(s) to close it. Perhaps OK and Cancel.

    I cannot reproduce it now because I can run that part only during trading hours on US stock exchanges between 9:30 AM and 4:30 PM EST Mon - Fri.

    Perhaps you can suggest how I can force it to throw an exception Then I will know exactly the location for the bug.

    Thanks.



  • nate-d-o-double-g

    BJohnson wrote:

    It feels to me that you are using a Substring function on a null/empty string. The parameter name being mentioned is the startIndex that is included in Substring.

    Hope that helps.

    That was fast. Thank you very much. It gives me some hope. Of course, there is a million substrings in the code but now it might be much easier to find the bug.



  • SIYER

    If you are doing lots of string parsing, regular expressions are usually faster and produce less complicated code.

  • HowardRichards

    not entirely sure. What are you trying to do really Is there some webservice you could use instead maybe databases or something, rather than reading strings and parsing it

  • Handerson

    Don't you log errors for such cases as yours. Add some logging for example in text file and when error occurs, write stack trace to see exactly on which line you got the bug.

  • saradha

    It feels to me that you are using a Substring function on a null/empty string. The parameter name being mentioned is the startIndex that is included in Substring.

    Hope that helps.



  • Philly10407

    boban.s wrote:
    Don't you log errors for such cases as yours. Add some logging for example in text file and when error occurs, write stack trace to see exactly on which line you got the bug.

    Actually the error disappeared as mysteriously as it appeared. I haven't seen it since Monday morning.

    What kind of logging are you talking about It is interesting. There was no exception thrown in the case in question. I do not know why. It could be because I put that block into a try... catch block or something. Sometimes I do it and then forget although there is no need to keep it there since the bug was found elsewhere and removed.

    Do you mean that there is a way to set up a system of logging every error for a debug run Where is the file with the error log I think I've used it in he past but now completely forgot where it is, etc.

    Answering another question: The input strings are variable length arrays of bytes. The longest is perhaps between 200 and 250 bytes. It is parsed by code provided by the server (a demo). I mutilated that part only to a small extent getting rid of fields I did not need.

    I use databases for input as well but this is a real-time data. I get information on the events a fraction of a second after they happened.

    The parsing is accompanied by conversion to float, DateTime, char, string, and other types depending on the field's meaning.

    Thanks.



  • Evan Mulawski

    You say you are "getting this message", but there is no source code location. Where are you getting the message Is an exception being thrown Are you seeing it in the output window

  • Index was out of range?