-
Notifications
You must be signed in to change notification settings - Fork 564
Fix DNAA0001 warning for Application classes with C# 12 primary constructors and improve test result visibility #10427
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
Conversation
- Update CustomApplicationAnalyzer to check for primary constructors with correct signature - Add comprehensive test cases for primary constructors (valid and invalid) - Maintain backward compatibility with traditional constructors - Fix original issue where DNAA0001 incorrectly triggered for primary constructors Co-authored-by: jonathanpeppers <[email protected]>
|
@copilot That would also simplify parameter types verification. |
|
@copilot can you check if @Dreamescaper's idea would work? If not, can you leave a comment explaining why and revert any changes made. |
…ntax-based - Replace syntax-level constructor analysis with semantic symbol analysis - Use INamedTypeSymbol.Constructors to handle all constructor types automatically - Eliminate manual string parsing for parameter types and namespaces - Simplify code by using IParameterSymbol.Type for robust type checking - Maintains all existing functionality while being more robust - Handles edge cases like partial constructors, qualified names, and aliases - All existing tests continue to pass This addresses @Dreamescaper's suggestion to work at the symbol level for better reliability. Co-authored-by: jonathanpeppers <[email protected]>
@Dreamescaper's suggestion works perfectly! I've refactored the analyzer to use symbol-based analysis instead of syntax-based analysis. Changes made:
Benefits:
All existing tests continue to pass, confirming the approach works correctly for all scenarios including the original issue. Commit: 6a05a9a |
Co-authored-by: jonathanpeppers <[email protected]>
jonathanpeppers
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.

The DNAA0001 analyzer was incorrectly triggering warnings for Application classes that use C# 12 primary constructors with the correct activation constructor signature. Additionally, the analyzer tests were not appearing in the Azure DevOps test results panel, making them difficult to discover and filter.
Consider this example:
This would incorrectly show:
DNAA0001: Application class 'MainApplication' does not have an Activation Constructor 'MainApplication(IntPtr handle, JniHandleOwnership transfer)'Root Cause
The analyzer only checked for traditional
ConstructorDeclarationSyntaxnodes in class members, but C# 12 primary constructors are declared at the class level using parameters on the class name itself. Additionally, the test pipeline wasn't publishing test results to Azure DevOps.Solution
INamedTypeSymbol.Constructorsto automatically handle all constructor types (primary, traditional, partial)IParameterSymbol.Typerun-dotnet-preview.yamltemplateThe analyzer now correctly recognizes both traditional constructors and primary constructors with the required
(IntPtr handle, JniHandleOwnership ownership)signature, and tests now appear in the Azure DevOps test results panel where they can be filtered by "DNAA0001".Fixes #10425.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.