Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I be concerned about "access to modified closure" in a linq queries?

Tags:

c#

linq

I have a linq query that is showing an error:

alt text

I see this error any time I try to access the variable I'm iterating over, if the source of the collection is a linq query. I guess this error is just telling me the variable could change, or something like that?

like image 243
Paul Fryer Avatar asked Nov 27 '10 12:11

Paul Fryer


1 Answers

This error is telling you that the reference to pubConfig inside your query will be using the value of pubConfig at the time the query is evaluated, and not at the time where you define it and store it in pubConfigSettings.

In practical terms, you will be OK if the query is evaluated "on the spot". If you keep it around for later evaluation, and the value of pubConfig changes in the meantime, you will encounter unexpected results.

like image 77
Jon Avatar answered Sep 28 '22 13:09

Jon