-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Description
Analyzer
Diagnostic ID: [IDE0031](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0031: Use null propagation
Analyzer source
.NET7
Describe the bug
Stumbled upon in dotnet/winforms#7902
The analyzer doesn't take into account #if DEBUG statements. Inside visual studio it doesn't suggest a code fix. But in CI build it fails.
public void Dispose()
{
if (_controlToLayout is not null)
{
_controlToLayout.ResumeLayout(_resumeLayout);
#if DEBUG
Debug.Assert(_controlToLayout.LayoutSuspendCount == _layoutSuspendCount, "Suspend/Resume layout mismatch!");
#endif
}
}Steps To Reproduce
Enable the analyzer as a warning or error and build a solution with a null check and a #if DEBUG statement.
Expected behavior
No build failure.
Actual behavior
Build Failure.
Additional context
This is blocking winforms uptake of the rule.
Copilot