Why does Visual Studio refer to the wrong string during exceptions?

Some simple lines of code below:

string[] countries = new string[1]; string[] cities = new string[1]; countries[0] = "USA"; countries[1] = "England"; cities[0] = "Chicago"; 

When Visual Studio throws a null exception, it refers to the following line, not the line where the exception occurred:
enter image description here

I know that the line number is correct when you view the details of the problem. However, I often spend more time than looking for the wrong variables, because the visual representation of the exception was incorrect.

Is it possible to configure VS or do something else to solve this problem? Is this a known issue or is it just me?

+6
source share
2 answers

This is apparently a known mistake .

+6
source

I'm not sure the @CodeNaked error is related to what you are experiencing. I know that I got this a lot when debugging code that has changed, and it needs to be recompiled. I would try to clean and restore.

+1
source

Source: https://habr.com/ru/post/894847/