Skip to content
This repository was archived by the owner on Nov 12, 2026. It is now read-only.

[release/8.0.1xx] Avoid 'Collection was modified' InvalidOperationException - #6937

Merged
carlossanlop merged 1 commit into
release/8.0.1xxfrom
backport/pr-6935-to-release/8.0.1xx
Sep 14, 2023
Merged

carlossanlop merged 1 commit into
release/8.0.1xxfrom
backport/pr-6935-to-release/8.0.1xx

Conversation

@github-actions

@github-actions github-actions Bot commented Sep 14, 2023 •

Copy link
Copy Markdown

Backport of #6935 to release/8.0.1xx

/cc @mavasani

Customer Impact

Couple of months back, we fixed a bunch of functionality issues in our dataflow analysis framework. One of those commits:
716272a caused a regression where in customers are now hitting new AD0001 analyzer exception diagnostics in different flow analysis based analyzers on RC1 bits, see #6929. We have received external as well internal reports for the same, but these are not that widespread because all the dataflow analysis based rules are disabled by default. However, any one who individually or bulk enables these rules via editorconfig or AnalysisLevel/AnalysisMode properties in MSBuild can potentially hit these exceptions.

Testing

I haven't been able to create a minimal repro that leads to this exception. However, the loop in question has been modified to no longer perform any state updates, so the underlying InvalidOperationException from collection modification should definitely no longer be thrown. I am planning to request the external and internal customers to try out the analyzer NuGet package from our public dotnet8 feed produced from the main branch to confirm the fix indeed resolves their AD0001.

I'll share an update here once I have done so and received responses. This was confirmed by the external customer here: #6929 (comment). I have sent out an email to the internal contact who hit the same issue to help validate.

Risk

This should be a pretty low risk fix as we are just changing to code to push all state updates after the loop which was enumerating the keys.

Fixes #6929

Ensure that we do not perform any state updates to the dataflow CoreAnalysisData inside the loop for the method `ClearOverlappingAnalysisDataForIndexedEntity`. We instead collect the key-value pairs to be updated in the loop, and perform these updates after the loop.

I haven't been able to come up with a minimal repro case that reproduces this exception, but the loop for which exception was generated can no longer perform any state updates, so we can be quite certain the underlying exception can no longer be thrown.
@github-actions
github-actions Bot requested a review from a team as a code owner September 14, 2023 04:31
@carlossanlop carlossanlop added the servicing-consider For backport requests to servicing branches. label Sep 14, 2023
@carlossanlop

Copy link
Copy Markdown

@jeffhandley @artl93 can you please take a look at this backport request?

@codecov

codecov Bot commented Sep 14, 2023

Copy link
Copy Markdown

Codecov Report

Merging #6937 (5da45a3) into release/8.0.1xx (249601b) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@               Coverage Diff                @@
##           release/8.0.1xx    #6937   +/-   ##
================================================
  Coverage            96.39%   96.40%           
================================================
  Files                 1402     1402           
  Lines               331854   331865   +11     
  Branches             11027    11028    +1     
================================================
+ Hits                319901   319919   +18     
+ Misses                9190     9184    -6     
+ Partials              2763     2762    -1     

@jeffhandley jeffhandley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good and logical to me. The risk for .NET 8 is low here and I support the backport as it should improve reliability.

@artl93 artl93 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

M2 Approved.

@carlossanlop
carlossanlop merged commit 4853a73 into release/8.0.1xx Sep 14, 2023
@carlossanlop
carlossanlop deleted the backport/pr-6935-to-release/8.0.1xx branch September 14, 2023 20:17
@rmsimpson

Copy link
Copy Markdown

Testing

I haven't been able to create a minimal repro that leads to this exception. However, the loop in question has been modified to no longer perform any state updates, so the underlying InvalidOperationException from collection modification should definitely no longer be thrown. I am planning to request the external and internal customers to try out the analyzer NuGet package from our public dotnet8 feed produced from the main branch to confirm the fix indeed resolves their AD0001.

Attached is a minimal repro @mavasani

RoslynBug.zip

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

servicing-consider For backport requests to servicing branches.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants