"Index was outside the array" when checking a variable without an array
I have a class "Address" that has the following validation:
if(thisAddress == null)
thisAddress = new Address();
When the code runs, I get "Index out of bounds of array" on the first line. If I remove the IF statement, I get an error on the second line.
The class comes from Linq to SQL, but I've extended it. This used to work, I don't know why it started suddenly. thisAddress is a private variable in UserControl.
Any ideas?
a source to share
Usually linq instructions are executed lazily or when they are used, not when you wrote the link. Therefore, it is entirely possible that the code behind the If statement is actually the cause of the error.
If so, you can try to step into the statement (it can use the equality check on the thisAddress class) and the debugger should show you the linq being executed.
The alternative and what I mainly use is disabling the debugger when exceptions are thrown rather than unhandled, which is a pretty good way to track down this kind of problem. (Debugger / Exceptions tick on when thrown in VS).
hope it helps
a source to share