Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Has the VB.NET compiler warning BC42324 been removed in VS2013?

I recently installed VS2013 (alongside a previous VS2010 installation) and noticed I no longer receive the compiler warning 'BC42324' (text below) when compiling identical VB.NET code (I recompiled back in VS2010 to confirm warning is still shown):

Using the iteration variable in a query expression may have unexpected results. Instead, create a local variable within the loop and assign it the value of the iteration variable.

Documentation on MSDN seems to suggest the warning is still included. I see/don't-see the warning with the following code :

Dim Numbers = {0, 1}
For Each index In Numbers
  Dim SumPlusIndex = Aggregate x In Numbers Select x + index Into Sum()
Next

Has this warning genuinely been removed? Is so how come? If not could there be other environmental differences between my VS2010 and VS2013 installation that might cause the difference?

like image 643
Simon B Avatar asked Nov 22 '25 01:11

Simon B


1 Answers

Yes, that's the infamous capture the for loop variable bug. It has bitten many programmers so Microsoft decided to do something about it. They solved it for a For Each loop, but not a For loop. You can still trigger the warning like this:

Sub Main()
    For ix As Integer = 1 To 10
        Dim dlg = Sub()
                      Console.WriteLine(ix)    '' Eek!
                  End Sub
        '' etc...
    Next
End Sub
like image 91
Hans Passant Avatar answered Nov 24 '25 22:11

Hans Passant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!