Add CA 2021 into CodeAnalysis config #82649
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
CA2021:
Do not call Enumerable.Cast<T> or Enumerable.OfType<T> with incompatible types
is a new analyzer that added in January.Because it is
Warns
by default it caused build failure on automation PR that updates analyzer feed which caused by some edge case scenario bug.Because the bug could cause a failure in other repos we lowered the severity of the analyzer until those bugs get fixed. Now the fix is ready for merge which also upgrades the severity into
Warning
back, we need to turn off the analyzer on test projects before merge because it would cause a warning for valid scenarios like:runtime/src/libraries/System.Linq/tests/CastTests.cs
Line 31 in 319fcd9
runtime/src/libraries/System.Linq/tests/OfTypeTests.cs
Lines 42 to 43 in 319fcd9