Fix MA0151 false positive on members of containing types and namespaces - #1592
Merged
Merged
Conversation
meziantou
marked this pull request as ready for review
September 23, 2026 04:12
This was referenced Sep 23, 2026
Bump Meziantou.Analyzer from 3.0.139 to 3.0.283
Analogy-LogViewer/Analogy.LogViewer.NLog.Targets#582
Closed
Closed
Bump Meziantou.Analyzer from 3.0.139 to 3.0.283
Analogy-LogViewer/Analogy.AspNetCore.LogProvider#563
Closed
Closed
Closed
Closed
Closed
Closed
Closed
This was referenced Oct 2, 2026
Bump Meziantou.Analyzer from 3.0.139 to 3.0.291
Analogy-LogViewer/Analogy.LogViewer.NLog.Targets#586
Open
Bump Meziantou.Analyzer from 3.0.139 to 3.0.291
Analogy-LogViewer/Analogy.AspNetCore.LogProvider#565
Open
Open
Open
Open
Open
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
MA0151 resolved the first name of a
DebuggerDisplayexpression only in the members of the type and in the global namespace. It reported valid expressions that use a type of the containing namespace or a static member of a containing type:Expected: no diagnostic. Actual: MA0151.
Fix
The first name is now looked up the way the C# compiler looks it up: in the type (including its base types), then in each containing type, then in each containing namespace, and finally in the global namespace and the keyword types, as before. The namespaces are converted to compilation namespaces so the types of referenced assemblies in the same namespace are found too. The rule documentation describes the lookup.
Tests
Added 3 tests to
DebuggerDisplayAttributeShouldContainValidExpressionsAnalyzerTests:CallStaticMethodOnTypeOfContainingNamespace(failed before the fix)StaticMemberOfContainingType(failed before the fix)UnknownMemberOfContainingNamespace, which checks that an unknown member of a type found in the containing namespace is still reportedThe class passes on roslyn5.9 and roslyn4.8 (93 tests each).