Repository navigation
[NET 11] Fix source-generated XAML diagnostic paths for ordinary and linked files - #39425
Conversation
Use the AdditionalText input path rather than the logical TargetPath in opt-in XAML line directives. Cover ordinary and linked XAML warning locations and document diagnostic navigation options. Partially addresses dotnet#35908. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Keep the proposed net11 PR limited to the source-generator fix and regression tests. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 39425Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 39425" |
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
🔵 Needs a closer look
No blocking defects were identified, but successful build and regression-test validation remain unverified.
0 open findings
What changed in this PR
Corrects source-generated XAML diagnostic paths for ordinary and linked files when line information is enabled, addressing the opt-in portion of #35908.
Changes:
- Uses the physical XAML input path in
#linedirectives. - Adds regression tests checking the mapped file and line for CS8622 warnings.
| File | Description |
|---|---|
| src/Controls/tests/SourceGen.UnitTests/InitializeComponent/LineInfoTests.cs | Tests diagnostic mapping for ordinary and linked XAML paths. |
| src/Controls/src/SourceGen/PrePost.cs | Emits physical input paths instead of logical target paths. |
🧠 Review effort: Balanced
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
There was a problem hiding this comment.
Expert Review — 0 findings
Reviewed commit 90537a7.
MauiBot
left a comment
There was a problem hiding this comment.
AI Review Summary
@sheiksyedm — new AI review results are available based on commit
90537a7.
🗂️ Review Sessions — click to expand
🚦 Gate — Test Before & After Fix
Gate Result: ✅ PASSED
Platform: ANDROID · Base: net11.0 · Merge base: 3f6af976
| Test | Without Fix (expect FAIL) | With Fix (expect PASS) |
|---|---|---|
🧪 LineInfoTests LineInfoTests |
✅ FAIL — 73s | ✅ PASS — 23s |
🔴 Without fix — 🧪 LineInfoTests: FAIL ✅ · 73s
Error-relevant lines (filtered from the build log):
at Microsoft.Maui.Controls.SourceGen.UnitTests.LineInfoTests.EventHandlerWarningMapsToPhysicalXamlFile(String targetPath) in /_/src/Controls/tests/SourceGen.UnitTests/InitializeComponent/LineInfoTests.cs:line 49
at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)
at InvokeStub_LineInfoTests.EventHandlerWarningMapsToPhysicalXamlFile(Object, Span`1)
at System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
🟢 With fix — 🧪 LineInfoTests: PASS ✅ · 23s
(no coded error found; showing last 1200 chars)
rtifacts/bin/SourceGen.UnitTests/Debug/net11.0/Microsoft.Maui.Controls.SourceGen.UnitTests.dll (.NETCoreApp,Version=v11.0)
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.8.2+699d445a1a (64-bit .NET 11.0.0-rtm.26480.113)
[xUnit.net 00:00:00.26] Discovering: Microsoft.Maui.Controls.SourceGen.UnitTests
[xUnit.net 00:00:00.57] Discovered: Microsoft.Maui.Controls.SourceGen.UnitTests
[xUnit.net 00:00:00.59] Starting: Microsoft.Maui.Controls.SourceGen.UnitTests
Passed Microsoft.Maui.Controls.SourceGen.UnitTests.LineInfoTests.EventHandlerWarningMapsToPhysicalXamlFile(targetPath: "Linked/Test.xaml") [4 s]
[xUnit.net 00:00:05.21] Finished: Microsoft.Maui.Controls.SourceGen.UnitTests
Passed Microsoft.Maui.Controls.SourceGen.UnitTests.LineInfoTests.EventHandlerWarningMapsToPhysicalXamlFile(targetPath: "Source/Test.xaml") [90 ms]
Passed Microsoft.Maui.Controls.SourceGen.UnitTests.LineInfoTests.LineInfoDisabledDefault [238 ms]
Passed Microsoft.Maui.Controls.SourceGen.UnitTests.LineInfoTests.DiagnosticShowsLocationInInputXamlFile [75 ms]
Test Run Successful.
Total tests: 4
Passed: 4
Total time: 6.0651 Seconds
📁 Fix files reverted (1 files)
src/Controls/src/SourceGen/PrePost.cs
📋 Pre-Flight — Context & Validation
Pre-Flight Context
Evidence snapshot: #39425 is an open PR targeting net11.0 (3f6af9762db18e6b251ec953e34ec0db9bfb1f7c) from head 90537a701230a74c510fb2c6bc8852f11672b1df. The immutable submitted diff contains two files, with 45 additions and 2 deletions. Its reported scope is the opt-in source-generated XAML line-information path behavior from #35908, not every symptom in that issue.
Reported problem
- #35908 reports that compiler warnings originating in generated XAML code—CS8622 is the example—refer to an intermediate
.xaml.xsg.csfile that the IDE cannot find, so navigating from the warning fails. - The issue describes a regression between .NET MAUI 10.0.70/71 and .NET 11 previews. It was reported or validated on Windows and Android; other platforms were not tested.
- The issue also raises generated-file retention with
EmitCompilerGeneratedFiles=true. The PR description says that behavior was not reproduced and is intentionally outside this change. - Source-generator line mapping is opt-in here.
ProjectItem.EnableLineInfodefaults tofalseunless per-fileLineInfometadata orMauiXamlLineInfoexplicitly enables it. - The linked Roslyn context, dotnet/roslyn#71202, states that relative paths in
#linedirectives for generated files have undefined behavior because generated files do not have a defined containing path.
Changed files and mechanism
-
src/Controls/src/SourceGen/PrePost.csPrePost.NewLineInfoemits a#linedirective around generated statements and restores#line defaultafterward.- The patch changes the directive path from
ProjectItem.TargetPathtoProjectItem.AdditionalText.Path. TargetPathcomes from compiler-visibleAdditionalFiles.TargetPathmetadata and may be a relative logical or linked-file path.AdditionalText.Pathis the path attached to the physical source-generator input.- Observed line-information call sites are in shared
SetPropertyHelpers.csand are gated byProjectItem.EnableLineInfo; no platform-specific handler code is modified.
-
src/Controls/tests/SourceGen.UnitTests/InitializeComponent/LineInfoTests.cs- Adds a theory covering logical target paths
Source/Test.xamlandLinked/Test.xaml. - Both cases supply the physical input as
<current directory>/Source/Test.xaml, enable nullable analysis, and deliberately produce CS8622 through an event handler whosesenderparameter is non-nullable. - The test compiles the generated trees, selects the single CS8622 diagnostic, and asserts that
GetMappedLineSpan()reports the physical path and zero-based line index3, corresponding to the<Button>line. - Existing tests already check that enabled line information emits a physical-path directive and that the default setting does not emit it.
- The test harness enables line information by default for its synthetic
AdditionalXamlFile; this differs from production’s disabled default.
- Adds a theory covering logical target paths
Platform-sensitive paths
- The implementation is shared source-generator code, so the changed mechanism is not Android-specific. For Android builds, path generation and diagnostic mapping occur on the build host; the relevant path is the host’s XAML path, not a device filesystem path.
Path.Combinemakes the new unit test host-separator aware, but the test directly injects an absolute physical path. It does not exercise an actual Android MSBuild item pipeline or IDE navigation.- The linked-file case specifically distinguishes the physical source path (
Source/Test.xaml) from its logical project target (Linked/Test.xaml). - Windows drive-letter/backslash paths motivated the original report. Linux/macOS-style paths are structurally covered by the host-neutral test construction, but no platform-specific IDE behavior is demonstrated.
- No Android, Windows, iOS, or Mac Catalyst implementation files are changed.
Validation context and requirements
- Required platform: Android.
- Provided Gate evidence: ✅ tests fail without the fix and pass with the fix. The Gate was not rerun.
- The targeted behavioral evidence should remain:
- line information explicitly enabled;
- ordinary and linked XAML inputs;
- CS8622 mapped to the physical XAML file and correct line;
- disabled/default line information unchanged.
- Android end-to-end validation would need to distinguish compiler mapping from IDE behavior: an actual Android-targeted build should emit the warning against the host’s physical XAML path, and IDE navigation should open that file for both ordinary and linked XAML.
- No commands, builds, tests, or additional CI checks were run for this context gathering. PR comments only establish that pipelines were started; their completion and results are unknown.
Remaining uncertainties
- Whether real Android MSBuild/Roslyn integration always supplies
AdditionalText.Pathas an absolute physical path, especially for linked files, is not established by the synthetic unit test. - IDE double-click/navigation behavior is not directly tested;
GetMappedLineSpan()verifies compiler mapping only. - The original issue’s default-setting scenario remains outside scope because line information still defaults to disabled.
- The reported
EmitCompilerGeneratedFilesretention behavior is untouched and remains unresolved or unverified by this patch. - Coverage is centered on one event-handler warning and two logical-path shapes; behavior for other generated diagnostics, unusual path characters, path mapping, deterministic builds/PDBs, and untested platforms remains unknown.
- The PR was reported as merge-blocked at the captured snapshot, but the reason was not established.
- This is pre-flight context from the submitted diff and nearby source, not an exhaustive code review or a comparative conclusion.
🔬 Code Review — Deep Analysis
Expert PR Evaluation — dotnet/maui PR #39425
Scope and Evidence Boundary
- Reviewed committed diff only: base
3f6af9762db18e6b251ec953e34ec0db9bfb1f7c→ head90537a701230a74c510fb2c6bc8852f11672b1df. - Changed files:
src/Controls/src/SourceGen/PrePost.cssrc/Controls/tests/SourceGen.UnitTests/InitializeComponent/LineInfoTests.cs
- No source edits performed.
- Gate status consumed as trusted input: fail-without-fix/pass-with-fix already passed; not rerun.
Independent Assessment (code-first)
What this changes
PrePost.NewLineInfo(...)now emits#lineusingprojectItem?.AdditionalText.Pathinstead ofprojectItem?.TargetPath.- New regression test
EventHandlerWarningMapsToPhysicalXamlFilevalidates mapped CS8622 warning location for both ordinary and linked logical target paths.
Inferred motivation
- Prevent Roslyn diagnostic mapping from resolving against logical/relative linked paths and instead map warnings back to the physical XAML file consumed by the generator.
Soundness
- Approach is minimal and correctly targeted to line-mapping source of truth.
- Unit coverage directly exercises the failure mode for linked path indirection and verifies mapped file+line.
Applicable Dimension / Platform Trace
- Activated by routing
- XAML & Bindings (#26): source generator line mapping behavior changed + source-gen unit coverage added.
- Logic and Correctness (#5): diagnostic path origin corrected and validated.
- Regression Prevention (#6): bug-fix regression test present for the reported scenario class.
- Complexity Reduction (#16): no unnecessary abstraction; direct substitution at emission point.
- Not activated
- Public API Surface, Handler Mapper, platform handler dimensions, Trim/AOT, Input/Path correctness (no external source→sink path construction introduced).
- Platform trace
- Required platform was Android; implementation is shared build-time source-gen logic (host-side path mapping), not runtime Android handler code.
- No Android-specific files changed.
Caller / Usage Trace
PrePost.NewLineInfo(...)call sites are inSetPropertyHelpers.csand are uniformly gated bycontext.ProjectItem.EnableLineInfo.- No changes to line-info default behavior were introduced by this PR.
Reconciliation with Supplied Narrative / Context
- PR narrative claims exactly this scoped fix: physical-path line mapping when
MauiXamlLineInfo=enable, with linked-file coverage. - Independent assessment agrees with stated scope.
- Claimed intentional non-goals (default-setting behavior and
EmitCompilerGeneratedFilesconcerns) are consistent with the diff.
Prior Review Reconciliation
Surfaces checked
- Top-level reviews (
pulls/{pr}/reviews) - Inline review comments (
pulls/{pr}/comments) - PR issue comments (
issues/{pr}/comments)
Result
- One top-level bot review noted “Needs a closer look” with 0 open findings.
- No inline findings present.
- Issue comments were pipeline/dogfood/status oriented; no unresolved concrete ❌ error-level code defects identified.
CI / Required-Check Status
gh pr checks --requiredcould not be used due unauthenticatedghin this environment.- Anonymous commit check-runs for head SHA show partial completion:
- completed/success: 3
- in_progress: 27
- Classification: undetermined / pending coverage (cannot assert required checks complete).
Findings (validated, file-line actionable)
- Blocking defects: none validated from current committed diff.
- Nonblocking uncertainties:
- CI completion state is pending/undetermined for this head.
- End-to-end IDE navigation behavior on all hosts remains broader than this unit-level mapping proof (outside this patch’s explicit scope).
Failure-Mode Probes
- Probe: Linked XAML logical path differs from physical source path.
Observed behavior: test validates mapped warning path equals physical path; this previously regressed mechanism is addressed. - Probe: Line info disabled/default path should remain unchanged.
Observed behavior: existingLineInfoDisabledDefaulttest still asserts no physical#lineemission under default mode. - Probe: Multiple generator call sites using
NewLineInfo.
Observed behavior: all call sites route through the same helper, so the path source fix propagates uniformly where line info is enabled.
External Output Contract
Not applicable (this PR does not add/change regex or token classification of external tool output).
Concrete Finding Evidence for Inline Review File
inline-findings.jsonreviewed and validated as a JSON array.- Concrete inline findings count: 0 (
[]).
Verdict
NEEDS_DISCUSSION
Confidence: low
Rationale
- Code-level review found no concrete blocking defect in the submitted changes.
- Required-check state is pending/undetermined in this environment; per evidence-first review policy, this blocks LGTM even when code findings are clean.
Refinement Threshold Decision
- Evidence threshold for a concrete actionable PR-plus-reviewer refinement: NOT MET.
- No validated file:line defect mechanism requiring refinement was found in current diff.
🛠️ Try-Fix — Analysis & Comparison
Alternative generation: not requested
Evidence-first mode intentionally omits routine Try-Fix attempts. This is not a failed
attempt, a completed alternative search, or evidence that alternatives have no value.
The expert review may still produce one evidence-backed PR refinement.
🏁 Report — Final Recommendation
⚠️ Final Recommendation: REQUEST CHANGES
Phase Status
| Phase | Status | Notes |
|---|---|---|
| Pre-Flight | ✅ COMPLETE | Trusted read-only evidence snapshot consumed |
| Code Review | NEEDS_DISCUSSION (low) | 0 blocking defects and 0 inline findings; required-check completion is pending/undetermined |
| Gate | ✅ PASSED | Android; tests fail without the fix and pass with it |
| Try-Fix | NOT REQUESTED | Evidence-first mode intentionally omitted alternative generation |
| Refinement | NOT GENERATED | No concrete source/test-backed defect met the refinement threshold |
| Report | ✅ COMPLETE | Raw pr is the sole candidate and winner |
Code Review and Candidate Comparison
The submitted pr is the only real candidate. The expert review found its AdditionalText.Path change minimal and sound, found no actionable file:line defect, and confirmed that the regression test covers ordinary and linked logical paths mapping to the physical XAML file. The trusted Gate passed. A pr-plus-reviewer candidate was not implemented because the evidence threshold was not met, and routine Try-Fix was not requested.
The raw pr therefore wins the comparison, but the expert verdict remains NEEDS_DISCUSSION: required-check completion for the submitted head is pending/undetermined. That evidence gap independently prevents an approval recommendation and does not demonstrate merge readiness.
Summary
Request changes pending complete required-check evidence for the submitted head. No source amendment is recommended from this review: the submitted fix is the best and only candidate, its focused regression behavior passed the trusted Gate, and no concrete code defect was found.
Root Cause
The source generator used ProjectItem.TargetPath in generated #line directives. That value can be a relative logical path, including a linked-file path, so Roslyn can resolve diagnostics beneath the generated source location instead of the physical XAML input. Using ProjectItem.AdditionalText.Path maps generated diagnostics to the physical file consumed by the generator.
Fix Quality
The fix is localized to the shared source-generator line-mapping helper and preserves the opt-in line-information behavior. The added theory verifies CS8622 mapping to the physical file and expected line for both ordinary and linked target paths, and the trusted Gate establishes fail-without-fix/pass-with-fix behavior. Broader IDE navigation behavior and the default-disabled line-information scenario remain explicitly outside this PR's scope; pending/undetermined required checks prevent claiming the submitted head is merge-ready.
📱 UI Tests — Button,Label,Layout
Detected UI test categories: Button,Label,Layout
[!WARNING]
No UI test results were produced for the detected categories. The PR build itself was
fine — the deep UI stage was skipped or interrupted on infrastructure (the
merge-for-testing step, emulator/simulator boot, or an Appium hang), not by this PR's code.
This is usually transient; the review re-runs on new commits (a maintainer can also re-run it).
🧭 Next Steps — review latest findings
No alternative fix was selected for this run. Review the session findings and CI results before merging.
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Description of Change
Correct source-generated XAML diagnostic paths when
MauiXamlLineInfo=enable.The generator currently writes
ProjectItem.TargetPathinto#linedirectives. This can be a relative logical path, including the link path for linked XAML files. Compiler warnings such as CS8622 then resolve underneath the generated source directory instead of pointing to the physical XAML input.Use
ProjectItem.AdditionalText.Pathfor line directives so diagnostics refer to the physical input file. Add regression coverage for ordinary and linked XAML paths. Only the generator fix and regression tests are included in this PR.Scope: XAML line information remains opt-in. This does not change
EmitCompilerGeneratedFilesdefaults, suppress nullability warnings, or claim to fix all IDE navigation scenarios in the original issue. On MAUI RC2,EmitCompilerGeneratedFiles=trueretained the generated file successfully; that reported failure was not reproduced.Issues Fixed
Fixed #35908
Note: This fix corrects physical XAML diagnostic paths with line information enabled. The issue is not fixed the default-setting IDE navigation.