-
Notifications
You must be signed in to change notification settings - Fork 470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CA2021: false positive with ValueType and Enum #7031
Comments
It seems the analyzer is complaining because of the |
n0099
added a commit
to n0099/open-tbm
that referenced
this issue
Mar 23, 2024
…ar to the nearest @ `RotateMatrix()` * fix the violation of Roslyn analyzer rule `S1244: Floating point numbers should not be tested for equality`: SonarSource/sonar-dotnet#2326 @ `PreprocessTextBoxes()` * using `RadiansToDegrees()` introduced in .NET 8: dotnet/runtime#86402 @ `GetRotationDegrees()` @ TesseractRecognizer.cs - the no longer effective suppression for Roslyn analyzer rule `SA1119:Statement should not use unnecessary parenthesis` due to DotNetAnalyzers/StyleCopAnalyzers#3730 @ `PaddleOcrRecognizerAndDetector.Initialize()` * add some ad-hoc suppressions for ReSharper inspection `StringLiteralTypo` @ imagePipeline * remove the no longer effective suppression of Roslyn analyzer rule `SA1003 // Symbols should be spaced correctly` and fix the violation of ReSharper inspection `RedundantCast` @ `ThreadLateCrawlerAndSaver.CrawlThread()` * suppress the violation of ReSharper inspection `InconsistentlySynchronizedField` @ `CrawlerLocks.AcquireFailed()` * suppress the violations of Roslyn analyzer rule `CA2021:Do not call Enumerable.Cast<T> or Enumerable.OfType<T> with incompatible types` due to it's false positive: dotnet/roslyn-analyzers#7031 @ `ResumeSuspendPostContentsPushingWorker.DoWork()` @ crawler * suppress the violations of Roslyn analyzer rule `S6667: Logging in a catch clause should pass the caught exception as a parameter` @ `ErrorableWorker.DoWorkWithExceptionLogging()` @ shared * suppress the violation of Roslyn analyzer rule `S6674:Log message template should be syntactically correct` and ReSharper inspection `RedundantUsingDirective` @ GlobalSuppressions.cs * fix all violations of Roslyn analyzer rule`CA1513: Use ObjectDisposedException throw helper` * setting `csharp_style_prefer_primary_constructors` @ .editorconfig * prevent `appsettings.*.json` get copied when publishing following https://weblog.west-wind.com/posts/2022/Aug/24/Keeping-Content-Out-of-the-Publish-Folder-for-WebDeploy#what-works-copytopublishdirectorynever @ `tbm.{Crawler,ImagePipeline}.csproj` + `tbm.sln.DotSettings` to store team-shared ReSharper options @ c#
fowl2
pushed a commit
to fowl2/roslyn-analyzers
that referenced
this issue
Feb 14, 2025
fowl2
added a commit
to fowl2/roslyn-analyzers
that referenced
this issue
Feb 14, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Analyzer
Diagnostic ID: CA2021 (no documentation yet):
Type 'U' is incompatible with type 'T' and cast attempts will throw InvalidCastException at runtime
Analyzer source
SDK: Built-in CA analyzers in .NET 8 SDK
Version: 8.0.100
Describe the bug
CA2021 incorrectly triggers when casting
ValueType
to aT : struct
, andEnum
to aT : struct, Enum
.Steps To Reproduce
Expected behavior
No warnings.
Actual behavior
CA2021 warnings in both
Cast<T>
calls.The text was updated successfully, but these errors were encountered: