"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?

0


a source to share


3 answers


Found it out. Apparently I left some key information. The code is inside the get {} section for the control property. The error was another line in the code (where I used split ()), but the debugger pointed to the first line of the get {} statement.



0


a source


The code is out of sync with the binary. Try to recompile the assembly containing usercontrol.



Anything changed in the DB that you think might break the LINQ to SQL mapping?

+1


a source


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

0


a source







All Articles