Skip to content

Fix source generator crash on null DataRow arguments - #11371

Open
Sergio Pedri (Sergio0694) wants to merge 3 commits into
microsoft:mainfrom
Sergio0694:user/sergiopedri/upstream-null-datarow
Open

Sergio Pedri (Sergio0694) wants to merge 3 commits into
microsoft:mainfrom
Sergio0694:user/sergiopedri/upstream-null-datarow

Conversation

@Sergio0694

@Sergio0694 Sergio Pedri (Sergio0694) commented Sep 18, 2026

Copy link
Copy Markdown
Member

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.

  • Short-circuit null arrays without enumerating their values, while checking accessibility of array element types used in generated casts and literals.
  • Match the unit-test DataRowAttribute stub to the real constructor overloads so null binds to the array overload instead of masking the bug.
  • Cover positional and named null arrays, nested arrays, inaccessible element types, and materialization as exactly one null argument.
  • Extend managed and Native AOT acceptance tests to verify the null row executes exactly once.
  • Make Windows crash-dump setup create the WER LocalDumps registry key when the hosted agent image does not provide it, allowing the build to proceed.

Minimal reproducer (no linked GitHub issue was provided):

[TestMethod]
[DataRow(null)]
public void AcceptsNull(string? value) => Assert.IsNull(value);

Validation

  • All 170 source-generator unit tests passed.
  • Managed source-generation acceptance test passed on net10.0.
  • Native AOT acceptance test passed on net10.0 / win-x64, including publishing with both MSBuild and compiler warnings treated as errors. No IL warning suppressions were added.
  • Re-ran MSTest.SourceGeneration.UnitTests after review: build and tests succeeded with 0 warnings and 0 errors.
  • Confirmed the Windows CI failure occurs before compilation on main and unrelated PRs when the LocalDumps registry key is absent; the setup script now creates it idempotently.

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>
Copilot AI balanced review requested due to automatic review settings September 18, 2026 05:45
@Sergio0694
Sergio Pedri (Sergio0694) marked this pull request as ready for review September 18, 2026 05:48
@github-actions github-actions Bot added the state/needs-review Awaiting review from the team. label Sep 18, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 DataRowAttribute stub.
  • 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.

@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 18, 2026
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 18, 2026
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>
Copilot AI review requested due to automatic review settings September 18, 2026 06:28
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 18, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 18, 2026
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 18, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 18, 2026
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 18, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused fix is consistent with Roslyn typed-constant behavior and has comprehensive regression coverage.

Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@github-actions

Copy link
Copy Markdown
Contributor

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 (failureOrRetryCount: 0, diagnosticCount: 0, slowRegressionCount: 0), and evidence collection was complete (evidenceIncomplete: false).

Why the build shows failed: The Windows Debug and Windows Release legs ended in failed state, but the associated timeline issues are all build/pipeline-infrastructure errors, not test failures:

  • Enable local dumps task failed (PowerShell exited with code 1) on both Windows legs.
  • Subsequent Gather logs for publish to artifacts / Publish pipeline artifacts / Publish logs steps failed with "Path does not exist" / "Not found SourceFolder" errors for artifacts\log and artifacts, consistent with the crash-dump setup failure preventing expected output folders from being created.
  • No crash dumps were produced (CrashDumps directories reported empty on both legs) and diagnostics.json is empty, so this isn't a test crash — it's the dump-enablement/log-publish tooling itself failing early in the job.

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.

🤖 Automated content by GitHub Copilot. Generated by the Pipeline Test Triage workflow. · copilot · auto · 48.4 AIC · ⌖ 6.37 AIC · ⊞ 8.9K

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The fix is focused, preserves generated semantics, and has comprehensive regression coverage.

Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@Evangelink Amaury Levé (Evangelink) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@microsoft-github-policy-service microsoft-github-policy-service Bot removed the state/needs-review Awaiting review from the team. label Sep 18, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot added the state/needs-review Awaiting review from the team. label Sep 18, 2026
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 18, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 18, 2026 09:18
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 18, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The fix is focused and comprehensively validates generation, compilation, materialization, and execution paths.

Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state/needs-review Awaiting review from the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants