Monday, March 8, 2010

A very inconvenient bug for Array.ForEach

Today I was trying to debug a user control and kept hitting an error being thrown on this line in the debugger:


          Controls.Add(cell = new HtmlGenericControl("span"));

 

To make it more confusing the message was:

Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: array

 

So now I have a double confusion – a statement that should never throw an error that complains about an ARRAY!!!!  

 

Finally, I got frustrated and just let the page error out when I noticed that the error shown on the page was at a different location:

 

Line 36: Array.ForEach(GetEmailAddresses(), item =>

Line 37: {

Line 38: sb.Append("<br/>");

 

In other words, the interactive debugger was pointing to the wrong line!  I am very interested to see if this problem will occur in RTM of VS2010. Be warned if you are using Array.ForEach!

No comments:

Post a Comment