Fix source generator crash on null DataRow arguments - #11371
Sergio Pedri (Sergio0694) wants to merge 3 commits into
Conversation
Handle null array constants without enumerating default values, while checking the accessibility of emitted array element types. Align the DataRow test stub with the real overloads and cover compilation, materialization, managed execution, and Native AOT. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The source file lacks its required BOM, and inaccessible null-array casts need direct regression coverage.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Fixes source-generator crashes when Roslyn represents null array attribute arguments with a default ImmutableArray.
Changes:
- Safely handles null arrays while validating element accessibility.
- Expands unit coverage and aligns the
DataRowAttributestub. - Verifies managed and Native AOT execution.
Review coverage
Generator logic, overload fidelity, regression tests, acceptance paths, and file encoding.File summaries
| File | Description |
|---|---|
AttributeMaterializationHelper.cs |
Handles null array constants safely. |
MSTestReflectionMetadataGeneratorTests.cs |
Adds null-array materialization tests. |
SourceGenerationNonAotTests.cs |
Verifies managed execution. |
NativeAotTests.cs |
Verifies Native AOT execution. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 2
- Review effort level: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Cover positional and named boxed null arrays of inaccessible enum types, including nested arrays, while retaining omission checks for non-null inaccessible arrays. Restore the source helper's UTF-8 BOM to match repository formatting. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Final test-triage resolution — Azure Pipelines build 1602053 This is a final analysis of the completed build (all legs finished). No open issue needed. Test results: Across all reported CTRF/TRX/JUnit records (32,661 total: 32,086 passed, 575 skipped), there were zero failed or retried tests. No flaky, crashed, or slow-regression signatures were identified ( Why the build shows failed: The Windows Debug and Windows Release legs ended in
This category of failure belongs to build/pipeline infrastructure analysis rather than test triage, so I'm not creating an issue from this agent. If it recurs across unrelated PRs/commits, it would warrant a separate infrastructure investigation (Build Failure Analysis) into the "Enable local dumps" step on the Windows legs. Conclusion: No actionable test regression, flake, or slowness found. Test suite is effectively clean for this revision.
|
Amaury Levé (Evangelink)
left a comment
There was a problem hiding this comment.
Note
🤖 Automated review by GitHub Copilot. To request a follow-up action, reply by tagging @copilot directly.
Review result: no actionable findings
The null-array handling is correctly ordered: TypedConstant.Values is no longer enumerated for null arrays, while the emitted cast's element type is still checked for accessibility. The updated DataRowAttribute stub matches the shipped overload set, and the tests verify generated-source compilation, exact one-null-argument materialization, nested arrays, named arguments, and inaccessible element types. Managed and Native AOT acceptance coverage also verifies that the row executes exactly once.
I independently built and ran MSTest.SourceGeneration.UnitTests at f9406bd0b340030e5da2d3b1a7f62a1fc1ec7e66; the project completed with 0 warnings and 0 errors. The current Windows CI failures occur in the pre-build Enable local dumps setup step because the LocalDumps registry path is absent; they are not caused by this diff.
Review coverage
- Scope and description alignment: clean; all four changed files support the stated fix.
- Algorithm and Roslyn typed-constant semantics: null, typed null, boxed null, nested array, empty array, and named-argument paths checked.
- Generated-code compatibility: emitted casts/literals, constructor overload binding, and inaccessible-type fallback checked.
- Public API and package compatibility: no public API or package metadata changes.
- Cross-TFM/AOT behavior: generator remains
netstandard2.0; managed and Native AOT consumer paths covered. - Test quality: assertions exercise compilation, emitted text, runtime materialization, discovery count, filter count, and exit code; no parallel-state or timing hazards introduced.
- Security, concurrency, resources, localization, CLI, MSBuild, and dependencies: no changed boundary or applicable regression.
- Existing review threads: both prior findings are resolved and were not duplicated.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Summary
Fixes the NullReferenceException from MSTestReflectionMetadataGenerator when an attribute argument is a null array, including [DataRow(null)]. Roslyn exposes a default ImmutableArray for these arguments, so enumerating TypedConstant.Values crashes the generator.
Minimal reproducer (no linked GitHub issue was provided):
Validation
MSTest.SourceGeneration.UnitTestsafter review: build and tests succeeded with 0 warnings and 0 errors.