0

I have a class "Address" that has the following check:

if(thisAddress == null)
   thisAddress = new Address();

When the code is run I get "Index was outside the bounds of the array" on the first line. If I remove the IF statement I get the error on the second line.

The class comes from Linq to SQL, but I have extended it. This worked before, I'm not sure why it started happening all of a sudden. thisAddress is a private variable in a UserControl.

Any ideas?

1
  • thisAddress is a variable of what type? Commented May 26, 2009 at 21:34

3 Answers 3

1

The code is not in sync with the binary.
Try recompiling the assembly that contains the usercontrol.

Has anything changed in the DB that you think can break the LINQ to SQL mapping?

Sign up to request clarification or add additional context in comments.

Comments

0

Typically linq statements are executed lazily, or when they are used rather than when you wrote the link. Therefore it is entirely possible that the code executing behind the If statement is actually where the fault lies.

If this is the case then you could try stepping into the statement (it could be using an equality check on the thisAddress class) and the debugger should show you the linq being executed.

An alternative and what I use mostly, is setting the debugger to break when exceptions are thrown rather than when they are unhandled, this is a pretty good way of tracking down this sort of issue. (Debugger/Exceptions tick when thrown in VS).

hope that helps

Comments

0

Figured it out. Apparently I left out a crucial piece of information. The code is inside the get {} section for a control property. The error was a different line in the code (where I was using a split()), but the debugger pointed to the first line of the get{} statement.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.