简体   繁体   中英

C# - Index was outside the bounds of the array

I am getting the following exception from my app: 在此输入图像描述

The line #1681 in the exception is pointing to this line in my app's code: 在此输入图像描述

Where iSC_Queue is a simple DTO class like this:

public class iSC_Queue
{
    public string ID                  { get; set; }
    public string TriggerTableName    { get; set; }
    public string TriggerTableID      { get; set; }
    public string TriggerTableIDValue { get; set; }
}

How is this possible? I am pretty sure, List initialisation doesn't produce this index out of bounds error. It must be happening somewhere inside my "Parse Queue Entries" code block.

How can I get C# exception to show the real line/stack trace where the error is?

It looks like it's not the line you are on, you may have be erroring on a different line.

You are seeing a message box so it must be in one of your try catch sections.

If you are parsing strings in the next section, quite likely you are attempting to split the string into a few pieces and you are not getting the number of sub strings you are expecting.

If you show more code we can help more?

try this

[Serializable()]
 public class iSC_Queue
 {
     public string ID { get; set; }
     public string TriggerTableName { get; set; }
     public string TriggerTableID { get; set; }
     public string TriggerTableIDValue { get; set; }
 }

Are you absolutely sure the screenshot of the message box is from the current version of your application (even if you did as little as remove or add empty lines to your code to make it more readable)?

It's quite possible for VS to run an older binary if there were compilation errors, and then the line numbers can be switched around. Otherwise, it shouldn't be possible for the application to point to that line.

The line number given in the exception message doesn't come from your application's .exe or .dll file; it comes from a .pdb file. If there isn't a .pdb file present, you don't get a line number at all, but just a byte offset from the start of the method.

If the line numbers you're getting don't seem to correspond to your source code, then either [a] the line number is correct but you're looking at the wrong version of the source code, or [b] the line number is incorrect because your application files and the .pdb file are out of sync (perhaps last time a new version was installed to the server, a new .pdb file wasn't installed, so the old one's still present).

Not an answer, per se - but a rebuttal to some of those I've read. I stumbled upon this, while trying to figure out why I get the same error with:

List<string> strTemp = new List<string>();

(edited for html rendering - missed the <string> tags) ON OCCASSION

at least, that's the line pointed to. I add the "on occasion" because it doesn't always happen. More often than not (barely, it's close), the code works as expected. Occasionally, however (for a few days at a time - weeks?) it will continually throw the above. Then, after a while, it stops. For the record, .pdb and .dll for web service deployed and dated identically, so no chance of a code mismatch.

Also note: this is the 4th version of the particular code I've launched (hidden feature until I get it right). In all 4 versions, the error would occasionally appear, and with all 4 versions, the error pointed to the above line (4 different line numbers, due to changes)

I've been leaning to windows/chrome updates causing the issue to come and go, but that's only a wild guess, because I've yet to find a better answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM