question

Jackson1990-7147 avatar image
0 Votes"
Jackson1990-7147 asked TimonYang-MSFT answered

Reason to Stacktrace

Hi,
Is it possible that error below

 at System.String.IndexOf(String value, Int32 startIndex, Int32 count, StringComparison comparisonType)
 at System.String.IndexOf(String value, Int32 startIndex)
 at Validate_File1.Program.Main(String[] args)

is due to this part of code? How to avoid it?

                                                  if (Pos4 - 3 - Pos3 > 0)
                                                      Email = l7[j].Substring(Pos3 + 2, Pos4 - 3 - Pos3);



dotnet-csharpdotnet-runtime
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

If you can provide a small code sample that demonstrates the problem would be best to assist. Otherwise use the Visual Studio debugger to examine values and have to question l7[j] name, change the name to say item17 and any one letter variable name should be more than one letter e.g. index.

0 Votes 0 ·

Hi,
Can you run project within the following versus relevant Text file?
https://1drv.ms/u/s!Ai8CrEskdewXwEXcXz6XsQd-Zuxt?e=8Pfn0f

0 Votes 0 ·

Hi Karen,
Can you run project within the following versus relevant Text file?
https://1drv.ms/u/s!Ai8CrEskdewXwEXcXz6XsQd-Zuxt?e=8Pfn0f

0 Votes 0 ·
TimonYang-MSFT avatar image
0 Votes"
TimonYang-MSFT answered

The text file you are reading has blank lines (Error.txt).

When the current line is a blank line, its length is 0, then use IndexOf(Char, Int32), startIndex is greater than the length of the string, this problem will occur.

Try to add a judgment, if the current line length is 0, use continue to enter the next round of loop.


If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

cheong00 avatar image
0 Votes"
cheong00 answered Jackson1990-7147 commented

No.

From the variable name, I think the line throwing error should be on assignment of value for Pos4, Pos3 or even Pos2 or Pos1/Pos instead. Try find "IndexOf" with Ctrl-F on that source file.

Also, if you think these lines throwing that error because of the line number in stack trace, chances are that the source code version is not the same as the binary throwing the exception.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks. Are you sure the line having error is having IndexOf being used in there? Why does search via IndexOf lead to error?

0 Votes 0 ·

If the stack trace show it's thrown by a method, the error must be in that method, or any code be called inside there. This is done by reflection.

On the other hand, if there is line number, the line number is generated by calculating byte offset from the start of method, then perform lookup on the PDB file if exists. Therefore if the PDB file is not the one generated with the binary, the line number will be wrong.

0 Votes 0 ·