Skip to content

[XAML] Generate global xmlns mappings from C# global usings - #40170

Merged
kubaflo merged 3 commits into
candidate/11.0.1xx-sr2from
stephanedelcroix-auto-global-xmlns-from-usings
Nov 12, 2026
Merged

kubaflo merged 3 commits into
candidate/11.0.1xx-sr2from
stephanedelcroix-auto-global-xmlns-from-usings

Conversation

@StephaneDelcroix

@StephaneDelcroix StephaneDelcroix commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

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!

Target Branch

This PR is for Initial base
New features, API changes, or .NET 12 work (including .NET 12 fixes) main
.NET 11 servicing fixes net11, for review
Older servicing, release integration, infrastructure, or documentation The branch designated for that work

For .NET 11 fixes, only a maintainer retargets the approved PR to the active
inflight lane and merges it after CI validates that final base. Do not merge
individual fixes directly into net11; agents must not retarget or merge.

Description of Change

C# namespace global using directives now add current-assembly types to the implicit global XAML namespace (http://schemas.microsoft.com/dotnet/maui/global, used when xmlns is omitted).

Included: handwritten global usings and MSBuild/SDK-generated ones (<Using Include="..." />).
Excluded: namespace/type aliases, extern-alias-qualified imports, global using static, ordinary output of other source generators in the same pass, and referenced-assembly types (existing explicit XmlnsDefinition mappings can still expose them). Explicit default namespaces such as http://schemas.microsoft.com/dotnet/2021/maui are unchanged.

Implementation:

  • XamlGenerator: semantic incremental provider collects active namespace global usings, normalizes, sorts, and deduplicates them. Emits Global.Usings.Xmlns.cs with [assembly: XmlnsDefinition(global, ns)] (no AssemblyName, so Runtime and XamlC resolve against the current assembly only).
  • Same-pass SourceGen resolution: imports flow into AssemblyAttributes.GlobalUsingNamespaces and resolve only through compilation.Assembly. Existing ambiguity diagnostics are preserved.
  • Incrementality: the compilation provider is combined with the namespace set, so editing usings invalidates the namespace and type caches. Method-body edits remain cached.
  • XamlC: the aggregated-xmlns guard now matches http:/https: instead of any CLR namespace starting with http, so namespaces such as http29708.Controls resolve.
  • Runtime XamlParser: the process-wide xmlns cache was filtered by the first assembly that gathered it, so one assembly's global mappings could resolve types for another (pre-existing, but more likely now). Definitions now keep their declaring assembly, and global mappings are filtered per current assembly in a cached view.
  • Docs: docs/specs/XamlCSharpExpressions.md.

Tests

  • SourceGen.UnitTests/GlobalUsingTests.cs: same-pass generation, escaped names, exclusions, current-assembly boundary with and without explicit mappings, extern alias, explicit MAUI default, ambiguity, edits/rebinding invalidation, deterministic ordering, and no import from other generators.
  • Xaml.UnitTests/Issues/Maui29708: Runtime, XamlC, and SourceGen inflation of a type and markup extension imported through a handwritten global using plus an MSBuild <Using>. A referenced-assembly type is rejected in Runtime and XamlC. RuntimeGlobalMappingsDoNotLeakToOtherAssemblies fails without the runtime cache fix.

Validation (macOS, platform TFMs disabled due to a local workload mismatch):

  • dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj full suite: passed — 641 passed, 40 skipped. It was run from a copied output path because XTypeMultiFileHotReloadTests fail when the path contains ~, independent of this change.
  • dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj --filter "FullyQualifiedName~Maui29708|FullyQualifiedName~Xmlns": passed — 42 passed.
  • Full Controls.Xaml.UnitTests: 2185 passed, 8 skipped, 2 failed (TwoWayDecimalBinding_*, locale-dependent on the en_BE test machine and unrelated to this change).

Issues Fixed

Fixes #29708

MykhailoDav and others added 2 commits November 11, 2026 22:52
### Description of Change

`Shell.FlyoutBackgroundColor` set from a `Style`, implicit or explicit,
was ignored. Only a value set directly on the `Shell` worked, and
`FlyoutBackground` worked from a `Style`.

**Root cause**

The `Shell` constructor binds `FlyoutBackgroundColor` to an
`AppThemeBinding` for the default white/black colors. It uses the public
`SetBinding`, which applies the binding with
`SetterSpecificity.FromBinding`, and a binding outranks every `Style`
setter; only a value set directly on the element is higher. So the
default always won over a `Style`.

**Fix**

The default binding is applied with the lowest specificity, `new
SetterSpecificity()`, through the same internal overload `Setter` uses
for bindings in styles. A `Style` setter or a value set directly on the
`Shell` now wins over it, and when nothing else sets the property the
theme colors still apply, including when the theme changes. The Material
3 path on Android, which doesn't create this binding, is unchanged.

**Tests**

In `AppThemeTests`:
- `StyleSetsShellFlyoutBackgroundColor`: an implicit `Shell` style sets
the color, and it stays after a theme change.
- `ShellFlyoutBackgroundColorFollowsTheThemeWithoutAStyle`: without a
style the default is still white in light and black in dark.

| | Without fix | With fix |
|---|---|---|
| `main` (4c74701) | First test fails: White instead of Red | Both
pass; Controls.Core.UnitTests 6735 passed |

### Issues Fixed

Fixes #9736

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
Namespace global usings (handwritten and MSBuild/SDK-generated) now add
current-assembly types to the implicit global XAML namespace. Aliases,
extern-alias imports, using static, and other generators' output are excluded.

Fixes #29708

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 12, 2026 10:03
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 40170

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 40170"

@azure-pipelines

This comment has been minimized.

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

No active review issues are identified for the global-using XAML namespace mapping changes.

No open issues 🎉

What changed in this PR

Addresses #29708 by generating implicit global XAML namespace mappings from C# namespace global using directives. This lets XAML elements and markup extensions resolve current-assembly types without explicit namespace declarations.

Changes:

  • Collects, normalizes, and emits global-using mappings, with same-pass SourceGen resolution and cache invalidation when imports change.
  • Corrects XamlC’s namespace guard so CLR namespaces beginning with http remain resolvable.
  • Adds coverage for import boundaries, exclusions, ambiguity, incremental updates, and all three XAML inflators, plus documentation.
File Description
src/​Controls/​tests/​Xaml.UnitTests/​Issues/​Maui29708External.rt.xaml Adds a referenced-assembly rejection fixture.
src/​Controls/​tests/​Xaml.UnitTests/​Issues/​Maui29708.xaml.cs Tests imported controls, markup extensions, and assembly boundaries.
src/​Controls/​tests/​Xaml.UnitTests/​Issues/​Maui29708.xaml Exercises imported types without explicit namespace declarations.
src/​Controls/​tests/​Xaml.UnitTests/​Controls.Xaml.UnitTests.csproj Adds an MSBuild-generated global using for testing.
src/​Controls/​tests/​SourceGen.UnitTests/​GlobalUsingTests.cs Covers generation, resolution, exclusions, and incremental behavior.
src/​Controls/​src/​SourceGen/​XmlTypeExtensions.cs Resolves globally imported types from the current assembly.
src/​Controls/​src/​SourceGen/​XamlGenerator.cs Collects global imports, emits mappings, and updates cache invalidation.
src/​Controls/​src/​SourceGen/​GeneratorHelpers.cs Passes imported namespaces into assembly metadata.
src/​Controls/​src/​SourceGen/​AssemblyAttributes.cs Stores global-using namespaces for type resolution.
src/​Controls/​src/​Build.Tasks/​XmlTypeExtensions.cs Restricts the aggregated-namespace guard to HTTP/HTTPS schemes.
docs/​specs/​XamlCSharpExpressions.md Documents global-using mappings and their scope.

Review effort: Balanced

The runtime XamlParser cached xmlns definitions process-wide, filtered by
the first assembly that gathered them, so global mappings from one assembly
could leak into another's type resolution. Keep each definition's source
assembly and filter global mappings per current assembly.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 12, 2026 10:46
@kubaflo

This comment has been minimized.

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Nov 12, 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

Source-loaded classless ResourceDictionary instances resolve types against the framework assembly rather than RootAssembly, dropping application global mappings and causing imported application types to fail resolution.

1 open issue

Review effort: Balanced


var types = xmlType.GetTypeReferences(
s_xmlnsDefinitions,
s_xmlnsDefinitions.For(currentAssembly),
@kubaflo

kubaflo commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

/rebase

@kubaflo

This comment has been minimized.

@azure-pipelines

This comment has been minimized.

@MauiBot

MauiBot commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

PR Test Gate

@StephaneDelcroix — existing-test verification for commit cc271744.

Result PASSED Platform Android Commit cc271744


🧪 Gate analysis — click to expand

✅ Passed. The selected verification satisfied the gate's passing conditions. Unmatched, skipped, or inconclusive groups are not passing evidence.

🧪 Unit tests
Test group Without fix With fix
GlobalUsingTests ✅ Failed as expected (85s) ✅ Passed (39s)
📄 XAML unit tests
Test group Without fix With fix
Maui29708 ⚠ Build blocked ⚠ Build blocked
Maui29708External ⚠ Build blocked ⚠ Build blocked
Execution log excerpts

Without fix GlobalUsingTests

     at Microsoft.Maui.Controls.Xaml.UnitTests.SourceGen.GlobalUsingTests.AssertNoErrors(ValueTuple`3 run) in /_/src/Controls/tests/SourceGen.UnitTests/GlobalUsingTests.cs:line 371
   at Microsoft.Maui.Controls.Xaml.UnitTests.SourceGen.GlobalUsingTests.GeneratesMappingsAndResolvesTypesInTheSamePass() in /_/src/Controls/tests/SourceGen.UnitTests/GlobalUsingTests.cs:line 59
   at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
     at Microsoft.Maui.Controls.Xaml.UnitTests.SourceGen.GlobalUsingTests.ImportedNamespaceOnlyAddsCurrentAssemblyTypes(String typeName, Boolean explicitMapping, Boolean shouldResolve) in /_/src/Controls/tests/SourceGen.UnitTests/GlobalUsingTests.cs:line 141
   at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)
   at InvokeStub_GlobalUsingTests.ImportedNamespaceOnlyAddsCurrentAssemblyTypes(Object, Span`1)
   at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
     at Microsoft.Maui.Controls.Xaml.UnitTests.SourceGen.GlobalUsingTests.ReportsAmbiguousTypesFromGlobalUsings() in /_/src/Controls/tests/SourceGen.UnitTests/GlobalUsingTests.cs:line 231
     at Microsoft.Maui.Controls.Xaml.UnitTests.SourceGen.GlobalUsingTests.IgnoresNonGlobalAliasesStaticImportsAndInactiveDirectives() in /_/src/Controls/tests/SourceGen.UnitTests/GlobalUsingTests.cs:line 91
     at System.Linq.ThrowHelper.ThrowNoElementsException()
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
   at System.Linq.ImmutableArrayExtensions.Single[T](ImmutableArray`1 immutableArray, Func`2 predicate)
   at Microsoft.Maui.Controls.Xaml.UnitTests.SourceGen.GlobalUsingTests.ReorderingAndDuplicatingUsingsKeepsGeneratedMappingsStable() in /_/src/Controls/tests/SourceGen.UnitTes

With fix GlobalUsingTests

s.SourceGen.GlobalUsingTests.ReportsAmbiguousTypesFromGlobalUsings [20 ms]
  Passed Microsoft.Maui.Controls.Xaml.UnitTests.SourceGen.GlobalUsingTests.IgnoresNonGlobalAliasesStaticImportsAndInactiveDirectives [28 ms]
  Passed Microsoft.Maui.Controls.Xaml.UnitTests.SourceGen.GlobalUsingTests.ReorderingAndDuplicatingUsingsKeepsGeneratedMappingsStable [75 ms]
  Passed Microsoft.Maui.Controls.Xaml.UnitTests.SourceGen.GlobalUsingTests.ExternAliasDoesNotImportSameNamedLocalNamespace [34 ms]
  Passed Microsoft.Maui.Controls.Xaml.UnitTests.SourceGen.GlobalUsingTests.ExplicitMauiDefaultDoesNotIncludeGlobalUsings [32 ms]
[xUnit.net 00:00:07.29]   Finished:    Microsoft.Maui.Controls.SourceGen.UnitTests
  Passed Microsoft.Maui.Controls.Xaml.UnitTests.SourceGen.GlobalUsingTests.RebindsAnUnchangedUsingWhenItsNamespaceIsAddedOrRemoved [107 ms]
  Passed Microsoft.Maui.Controls.Xaml.UnitTests.SourceGen.GlobalUsingTests.GlobalUsingEditsInvalidateMappingsAndTypeResolution [178 ms]
  Passed Microsoft.Maui.Controls.Xaml.UnitTests.SourceGen.GlobalUsingTests.DoesNotImportUsingsGeneratedByAnotherGeneratorInTheSamePass [17 ms]
Test Run Successful.
Total tests: 13
     Passed: 13
 Total time: 8.7464 Seconds

Without fix Maui29708

CSC : error MAUIX2000: Cannot resolve type "http://schemas.microsoft.com/dotnet/maui/global:Maui29708Control". [/home/vsts/work/1/s/src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj]
CSC : error MAUIX2000: Cannot resolve type "http://schemas.microsoft.com/dotnet/maui/global:Maui29708HttpControl". [/home/vsts/work/1/s/src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj]
/home/vsts/work/1/s/src/Controls/tests/Xaml.UnitTests/Issues/Maui29708.xaml(1,1): error MAUIG1001: An error occured while parsing Xaml: The given key 'Microsoft.Maui.Controls.Xaml.ElementNode' was not present in the dictionary. File: /home/vsts/work/1/s/src/Controls/tests/Xaml.UnitTests/Issues/Maui29708.xaml. [/home/vsts/work/1/s/src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj]
/home/vsts/work/1/s/src/Controls/tests/Xaml.UnitTests/Generated/Microsoft.Maui.Controls.SourceGen/Microsoft.Maui.Controls.SourceGen.XamlGenerator/Issues_Maui29708.xaml.sg.cs(31,24): error CS8795: Partial method 'Maui29708.InitializeComponentSourceGen()' must have an implementation part because it has accessibility modifiers. [/home/vsts/work/1/s/src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj]

With fix Maui29708

CSC : error MAUIX2000: Cannot resolve type "http://schemas.microsoft.com/dotnet/maui/global:Maui29708Control". [/home/vsts/work/1/s/src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj]
CSC : error MAUIX2000: Cannot resolve type "http://schemas.microsoft.com/dotnet/maui/global:Maui29708HttpControl". [/home/vsts/work/1/s/src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj]
/home/vsts/work/1/s/src/Controls/tests/Xaml.UnitTests/Issues/Maui29708.xaml(1,1): error MAUIG1001: An error occured while parsing Xaml: The given key 'Microsoft.Maui.Controls.Xaml.ElementNode' was not present in the dictionary. File: /home/vsts/work/1/s/src/Controls/tests/Xaml.UnitTests/Issues/Maui29708.xaml. [/home/vsts/work/1/s/src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj]
/home/vsts/work/1/s/src/Controls/tests/Xaml.UnitTests/Generated/Microsoft.Maui.Controls.SourceGen/Microsoft.Maui.Controls.SourceGen.XamlGenerator/Issues_Maui29708.xaml.sg.cs(31,24): error CS8795: Partial method 'Maui29708.InitializeComponentSourceGen()' must have an implementation part because it has accessibility modifiers. [/home/vsts/work/1/s/src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj]

PR head: cc271744.

Without-fix baseline: 9291bfb2.

@MauiBot MauiBot added s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix) and removed s/agent-review-in-progress AI review is currently running for this PR labels Nov 12, 2026
@kubaflo
kubaflo changed the base branch from main to candidate/11.0.1xx-sr2 November 12, 2026 11:23
@kubaflo
kubaflo merged commit 706b461 into candidate/11.0.1xx-sr2 Nov 12, 2026
16 of 155 checks passed
@kubaflo
kubaflo deleted the stephanedelcroix-auto-global-xmlns-from-usings branch November 12, 2026 11:24
kubaflo added a commit that referenced this pull request Nov 13, 2026
<!-- Please let the below note in for people that find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
Open .NET 11 fix PRs against net11 for review; target main for
next-major features.
After approval, a maintainer manually retargets the fix PR to the active
inflight
branch and merges it directly there. Do not merge individual fixes into
net11.
Bots must not retarget or merge. Candidate integration into net11 and
release/*
changes are separate, explicitly coordinated release work.
-->

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

### Description of Change

Revert #39839 on `main` as requested. This restores the previous
behavior: a `Style` cannot override the default
`Shell.FlyoutBackgroundColor` binding until the candidate fix is
forwarded to `main`.

The identical implementation and regression tests are already on
`candidate/11.0.1xx-sr2`, where they were included in #40170 (commit
`706b461e9296fd30f7ff3c057dacf2025d60a698`). A separate candidate PR for
the same patch would be empty, so this PR changes only `main`.

### Validation

- Verified the commit is the exact inverse of
`9291bfb20edde2cc822b8e2a110f63d2b3425e09`; both changed files match
their pre-fix blobs.
- `dotnet build Microsoft.Maui.BuildTasks.slnf -c Debug
-p:IncludeIosTargetFrameworks=false
-p:IncludeAndroidTargetFrameworks=false
-p:IncludeMacCatalystTargetFrameworks=false
-p:IncludeWindowsTargetFrameworks=false
-p:IncludeTizenTargetFrameworks=false -p:TreatWarningsAsErrors=false
--verbosity quiet` — passed.
- `dotnet test
src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj
--no-restore -c Debug -p:IncludeIosTargetFrameworks=false
-p:IncludeAndroidTargetFrameworks=false
-p:IncludeMacCatalystTargetFrameworks=false
-p:IncludeWindowsTargetFrameworks=false
-p:IncludeTizenTargetFrameworks=false -p:TreatWarningsAsErrors=false
--filter 'FullyQualifiedName~AppThemeTests' --verbosity quiet` — passed:
15 tests before the revert and 13 after removal of the two reverted
tests.
- `dotnet test
src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj
--no-build --no-restore -c Debug -p:IncludeIosTargetFrameworks=false
-p:IncludeAndroidTargetFrameworks=false
-p:IncludeMacCatalystTargetFrameworks=false
-p:IncludeWindowsTargetFrameworks=false
-p:IncludeTizenTargetFrameworks=false -p:TreatWarningsAsErrors=false
--filter 'FullyQualifiedName~ShellTests|FullyQualifiedName~StyleTests'
--verbosity quiet` — passed: 147 tests.
- With the two original regression tests temporarily retained against
the reverted implementation, `dotnet test
src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj
--no-restore -c Debug -p:IncludeIosTargetFrameworks=false
-p:IncludeAndroidTargetFrameworks=false
-p:IncludeMacCatalystTargetFrameworks=false
-p:IncludeWindowsTargetFrameworks=false
-p:IncludeTizenTargetFrameworks=false -p:TreatWarningsAsErrors=false
--filter
'FullyQualifiedName~StyleSetsShellFlyoutBackgroundColor|FullyQualifiedName~ShellFlyoutBackgroundColorFollowsTheThemeWithoutAStyle'
--logger 'console;verbosity=normal'` — expected failure: the style test
received white instead of red; the default-theme test passed. The
temporarily retained tests were removed again before committing.
- The combined selection `dotnet test
src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj
--no-restore -c Debug -p:IncludeIosTargetFrameworks=false
-p:IncludeAndroidTargetFrameworks=false
-p:IncludeMacCatalystTargetFrameworks=false
-p:IncludeWindowsTargetFrameworks=false
-p:IncludeTizenTargetFrameworks=false -p:TreatWarningsAsErrors=false
--filter
'FullyQualifiedName~AppThemeTests|FullyQualifiedName~ShellTests|FullyQualifiedName~StyleTests'
--verbosity quiet` failed
`CorrectDefaultRadioButtonThemeColorsInLightAndDarkModes` (159 passed, 1
failed). The same failure occurred with the original patch restored on
the unmodified `main` baseline (161 passed, 1 failed); the isolated
selections above pass.
- `dotnet format Microsoft.Maui.sln --no-restore --verify-no-changes
--include src/Controls/src/Core/Shell/Shell.cs
src/Controls/tests/Core.UnitTests/AppThemeTests.cs --exclude
Templates/src --exclude-diagnostics CA1822 --verbosity quiet` — passed.

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Related to #9736; this revert intentionally restores the issue on
`main`.

<!--
Verify the target branch follows the release workflow in
docs/ReleaseBranchWorkflow.md.
Infrastructure and documentation changes should target the branch where
they apply.
-->

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
SuthiYuvaraj pushed a commit to SuthiYuvaraj/maui that referenced this pull request Nov 13, 2026
<!-- Please let the below note in for people that find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
Open .NET 11 fix PRs against net11 for review; target main for
next-major features.
After approval, a maintainer manually retargets the fix PR to the active
inflight
branch and merges it directly there. Do not merge individual fixes into
net11.
Bots must not retarget or merge. Candidate integration into net11 and
release/*
changes are separate, explicitly coordinated release work.
-->

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

### Description of Change

Revert dotnet#39839 on `main` as requested. This restores the previous
behavior: a `Style` cannot override the default
`Shell.FlyoutBackgroundColor` binding until the candidate fix is
forwarded to `main`.

The identical implementation and regression tests are already on
`candidate/11.0.1xx-sr2`, where they were included in dotnet#40170 (commit
`706b461e9296fd30f7ff3c057dacf2025d60a698`). A separate candidate PR for
the same patch would be empty, so this PR changes only `main`.

### Validation

- Verified the commit is the exact inverse of
`9291bfb20edde2cc822b8e2a110f63d2b3425e09`; both changed files match
their pre-fix blobs.
- `dotnet build Microsoft.Maui.BuildTasks.slnf -c Debug
-p:IncludeIosTargetFrameworks=false
-p:IncludeAndroidTargetFrameworks=false
-p:IncludeMacCatalystTargetFrameworks=false
-p:IncludeWindowsTargetFrameworks=false
-p:IncludeTizenTargetFrameworks=false -p:TreatWarningsAsErrors=false
--verbosity quiet` — passed.
- `dotnet test
src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj
--no-restore -c Debug -p:IncludeIosTargetFrameworks=false
-p:IncludeAndroidTargetFrameworks=false
-p:IncludeMacCatalystTargetFrameworks=false
-p:IncludeWindowsTargetFrameworks=false
-p:IncludeTizenTargetFrameworks=false -p:TreatWarningsAsErrors=false
--filter 'FullyQualifiedName~AppThemeTests' --verbosity quiet` — passed:
15 tests before the revert and 13 after removal of the two reverted
tests.
- `dotnet test
src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj
--no-build --no-restore -c Debug -p:IncludeIosTargetFrameworks=false
-p:IncludeAndroidTargetFrameworks=false
-p:IncludeMacCatalystTargetFrameworks=false
-p:IncludeWindowsTargetFrameworks=false
-p:IncludeTizenTargetFrameworks=false -p:TreatWarningsAsErrors=false
--filter 'FullyQualifiedName~ShellTests|FullyQualifiedName~StyleTests'
--verbosity quiet` — passed: 147 tests.
- With the two original regression tests temporarily retained against
the reverted implementation, `dotnet test
src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj
--no-restore -c Debug -p:IncludeIosTargetFrameworks=false
-p:IncludeAndroidTargetFrameworks=false
-p:IncludeMacCatalystTargetFrameworks=false
-p:IncludeWindowsTargetFrameworks=false
-p:IncludeTizenTargetFrameworks=false -p:TreatWarningsAsErrors=false
--filter
'FullyQualifiedName~StyleSetsShellFlyoutBackgroundColor|FullyQualifiedName~ShellFlyoutBackgroundColorFollowsTheThemeWithoutAStyle'
--logger 'console;verbosity=normal'` — expected failure: the style test
received white instead of red; the default-theme test passed. The
temporarily retained tests were removed again before committing.
- The combined selection `dotnet test
src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj
--no-restore -c Debug -p:IncludeIosTargetFrameworks=false
-p:IncludeAndroidTargetFrameworks=false
-p:IncludeMacCatalystTargetFrameworks=false
-p:IncludeWindowsTargetFrameworks=false
-p:IncludeTizenTargetFrameworks=false -p:TreatWarningsAsErrors=false
--filter
'FullyQualifiedName~AppThemeTests|FullyQualifiedName~ShellTests|FullyQualifiedName~StyleTests'
--verbosity quiet` failed
`CorrectDefaultRadioButtonThemeColorsInLightAndDarkModes` (159 passed, 1
failed). The same failure occurred with the original patch restored on
the unmodified `main` baseline (161 passed, 1 failed); the isolated
selections above pass.
- `dotnet format Microsoft.Maui.sln --no-restore --verify-no-changes
--include src/Controls/src/Core/Shell/Shell.cs
src/Controls/tests/Core.UnitTests/AppThemeTests.cs --exclude
Templates/src --exclude-diagnostics CA1822 --verbosity quiet` — passed.

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Related to dotnet#9736; this revert intentionally restores the issue on
`main`.

<!--
Verify the target branch follows the release workflow in
docs/ReleaseBranchWorkflow.md.
Infrastructure and documentation changes should target the branch where
they apply.
-->

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Nov 13, 2026
<!-- Please let the below note in for people that find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

### Description of Change

C# namespace `global using` directives now add **current-assembly**
types to the implicit global XAML namespace
(`http://schemas.microsoft.com/dotnet/maui/global`, used when `xmlns` is
omitted).

**Included:** handwritten global usings and MSBuild/SDK-generated ones
(`<Using Include="..." />`).
**Excluded:** namespace/type aliases, extern-alias-qualified imports,
`global using static`, ordinary output of other source generators in the
same pass, and referenced-assembly types (existing explicit
`XmlnsDefinition` mappings can still expose them). Explicit default
namespaces such as `http://schemas.microsoft.com/dotnet/2021/maui` are
unchanged.

Implementation:
- `XamlGenerator`: semantic incremental provider collects active
namespace global usings, normalizes, sorts, and deduplicates them. Emits
`Global.Usings.Xmlns.cs` with `[assembly: XmlnsDefinition(global, ns)]`
(no `AssemblyName`, so Runtime and XamlC resolve against the current
assembly only).
- Same-pass SourceGen resolution: imports flow into
`AssemblyAttributes.GlobalUsingNamespaces` and resolve only through
`compilation.Assembly`. Existing ambiguity diagnostics are preserved.
- Incrementality: the compilation provider is combined with the
namespace set, so editing usings invalidates the namespace and type
caches. Method-body edits remain cached.
- XamlC: the aggregated-xmlns guard now matches `http:`/`https:` instead
of any CLR namespace starting with `http`, so namespaces such as
`http29708.Controls` resolve.
- Runtime `XamlParser`: the process-wide xmlns cache was filtered by the
first assembly that gathered it, so one assembly's global mappings could
resolve types for another (pre-existing, but more likely now).
Definitions now keep their declaring assembly, and global mappings are
filtered per current assembly in a cached view.
- Docs: `docs/specs/XamlCSharpExpressions.md`.

### Tests
- `SourceGen.UnitTests/GlobalUsingTests.cs`: same-pass generation,
escaped names, exclusions, current-assembly boundary with and without
explicit mappings, extern alias, explicit MAUI default, ambiguity,
edits/rebinding invalidation, deterministic ordering, and no import from
other generators.
- `Xaml.UnitTests/Issues/Maui29708`: Runtime, XamlC, and SourceGen
inflation of a type and markup extension imported through a handwritten
global using plus an MSBuild `<Using>`. A referenced-assembly type is
rejected in Runtime and XamlC.
`RuntimeGlobalMappingsDoNotLeakToOtherAssemblies` fails without the
runtime cache fix.

Validation (macOS, platform TFMs disabled due to a local workload
mismatch):
- `dotnet test
src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj` full
suite: **passed** — 641 passed, 40 skipped. It was run from a copied
output path because `XTypeMultiFileHotReloadTests` fail when the path
contains `~`, independent of this change.
- `dotnet test
src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj
--filter "FullyQualifiedName~Maui29708|FullyQualifiedName~Xmlns"`:
**passed** — 42 passed.
- Full `Controls.Xaml.UnitTests`: 2185 passed, 8 skipped, 2 failed
(`TwoWayDecimalBinding_*`, locale-dependent on the `en_BE` test machine
and unrelated to this change).

### Issues Fixed

Fixes #29708

---------

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Nov 16, 2026
<!-- Please let the below note in for people that find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

### Description of Change

C# namespace `global using` directives now add **current-assembly**
types to the implicit global XAML namespace
(`http://schemas.microsoft.com/dotnet/maui/global`, used when `xmlns` is
omitted).

**Included:** handwritten global usings and MSBuild/SDK-generated ones
(`<Using Include="..." />`).
**Excluded:** namespace/type aliases, extern-alias-qualified imports,
`global using static`, ordinary output of other source generators in the
same pass, and referenced-assembly types (existing explicit
`XmlnsDefinition` mappings can still expose them). Explicit default
namespaces such as `http://schemas.microsoft.com/dotnet/2021/maui` are
unchanged.

Implementation:
- `XamlGenerator`: semantic incremental provider collects active
namespace global usings, normalizes, sorts, and deduplicates them. Emits
`Global.Usings.Xmlns.cs` with `[assembly: XmlnsDefinition(global, ns)]`
(no `AssemblyName`, so Runtime and XamlC resolve against the current
assembly only).
- Same-pass SourceGen resolution: imports flow into
`AssemblyAttributes.GlobalUsingNamespaces` and resolve only through
`compilation.Assembly`. Existing ambiguity diagnostics are preserved.
- Incrementality: the compilation provider is combined with the
namespace set, so editing usings invalidates the namespace and type
caches. Method-body edits remain cached.
- XamlC: the aggregated-xmlns guard now matches `http:`/`https:` instead
of any CLR namespace starting with `http`, so namespaces such as
`http29708.Controls` resolve.
- Runtime `XamlParser`: the process-wide xmlns cache was filtered by the
first assembly that gathered it, so one assembly's global mappings could
resolve types for another (pre-existing, but more likely now).
Definitions now keep their declaring assembly, and global mappings are
filtered per current assembly in a cached view.
- Docs: `docs/specs/XamlCSharpExpressions.md`.

### Tests
- `SourceGen.UnitTests/GlobalUsingTests.cs`: same-pass generation,
escaped names, exclusions, current-assembly boundary with and without
explicit mappings, extern alias, explicit MAUI default, ambiguity,
edits/rebinding invalidation, deterministic ordering, and no import from
other generators.
- `Xaml.UnitTests/Issues/Maui29708`: Runtime, XamlC, and SourceGen
inflation of a type and markup extension imported through a handwritten
global using plus an MSBuild `<Using>`. A referenced-assembly type is
rejected in Runtime and XamlC.
`RuntimeGlobalMappingsDoNotLeakToOtherAssemblies` fails without the
runtime cache fix.

Validation (macOS, platform TFMs disabled due to a local workload
mismatch):
- `dotnet test
src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj` full
suite: **passed** — 641 passed, 40 skipped. It was run from a copied
output path because `XTypeMultiFileHotReloadTests` fail when the path
contains `~`, independent of this change.
- `dotnet test
src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj
--filter "FullyQualifiedName~Maui29708|FullyQualifiedName~Xmlns"`:
**passed** — 42 passed.
- Full `Controls.Xaml.UnitTests`: 2185 passed, 8 skipped, 2 failed
(`TwoWayDecimalBinding_*`, locale-dependent on the `en_BE` test machine
and unrelated to this change).

### Issues Fixed

Fixes #29708

---------

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Nov 16, 2026
<!-- Please let the below note in for people that find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

### Description of Change

C# namespace `global using` directives now add **current-assembly**
types to the implicit global XAML namespace
(`http://schemas.microsoft.com/dotnet/maui/global`, used when `xmlns` is
omitted).

**Included:** handwritten global usings and MSBuild/SDK-generated ones
(`<Using Include="..." />`).
**Excluded:** namespace/type aliases, extern-alias-qualified imports,
`global using static`, ordinary output of other source generators in the
same pass, and referenced-assembly types (existing explicit
`XmlnsDefinition` mappings can still expose them). Explicit default
namespaces such as `http://schemas.microsoft.com/dotnet/2021/maui` are
unchanged.

Implementation:
- `XamlGenerator`: semantic incremental provider collects active
namespace global usings, normalizes, sorts, and deduplicates them. Emits
`Global.Usings.Xmlns.cs` with `[assembly: XmlnsDefinition(global, ns)]`
(no `AssemblyName`, so Runtime and XamlC resolve against the current
assembly only).
- Same-pass SourceGen resolution: imports flow into
`AssemblyAttributes.GlobalUsingNamespaces` and resolve only through
`compilation.Assembly`. Existing ambiguity diagnostics are preserved.
- Incrementality: the compilation provider is combined with the
namespace set, so editing usings invalidates the namespace and type
caches. Method-body edits remain cached.
- XamlC: the aggregated-xmlns guard now matches `http:`/`https:` instead
of any CLR namespace starting with `http`, so namespaces such as
`http29708.Controls` resolve.
- Runtime `XamlParser`: the process-wide xmlns cache was filtered by the
first assembly that gathered it, so one assembly's global mappings could
resolve types for another (pre-existing, but more likely now).
Definitions now keep their declaring assembly, and global mappings are
filtered per current assembly in a cached view.
- Docs: `docs/specs/XamlCSharpExpressions.md`.

### Tests
- `SourceGen.UnitTests/GlobalUsingTests.cs`: same-pass generation,
escaped names, exclusions, current-assembly boundary with and without
explicit mappings, extern alias, explicit MAUI default, ambiguity,
edits/rebinding invalidation, deterministic ordering, and no import from
other generators.
- `Xaml.UnitTests/Issues/Maui29708`: Runtime, XamlC, and SourceGen
inflation of a type and markup extension imported through a handwritten
global using plus an MSBuild `<Using>`. A referenced-assembly type is
rejected in Runtime and XamlC.
`RuntimeGlobalMappingsDoNotLeakToOtherAssemblies` fails without the
runtime cache fix.

Validation (macOS, platform TFMs disabled due to a local workload
mismatch):
- `dotnet test
src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj` full
suite: **passed** — 641 passed, 40 skipped. It was run from a copied
output path because `XTypeMultiFileHotReloadTests` fail when the path
contains `~`, independent of this change.
- `dotnet test
src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj
--filter "FullyQualifiedName~Maui29708|FullyQualifiedName~Xmlns"`:
**passed** — 42 passed.
- Full `Controls.Xaml.UnitTests`: 2185 passed, 8 skipped, 2 failed
(`TwoWayDecimalBinding_*`, locale-dependent on the `en_BE` test machine
and unrelated to this change).

### Issues Fixed

Fixes #29708

---------

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Nov 17, 2026
<!-- Please let the below note in for people that find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

### Description of Change

C# namespace `global using` directives now add **current-assembly**
types to the implicit global XAML namespace
(`http://schemas.microsoft.com/dotnet/maui/global`, used when `xmlns` is
omitted).

**Included:** handwritten global usings and MSBuild/SDK-generated ones
(`<Using Include="..." />`).
**Excluded:** namespace/type aliases, extern-alias-qualified imports,
`global using static`, ordinary output of other source generators in the
same pass, and referenced-assembly types (existing explicit
`XmlnsDefinition` mappings can still expose them). Explicit default
namespaces such as `http://schemas.microsoft.com/dotnet/2021/maui` are
unchanged.

Implementation:
- `XamlGenerator`: semantic incremental provider collects active
namespace global usings, normalizes, sorts, and deduplicates them. Emits
`Global.Usings.Xmlns.cs` with `[assembly: XmlnsDefinition(global, ns)]`
(no `AssemblyName`, so Runtime and XamlC resolve against the current
assembly only).
- Same-pass SourceGen resolution: imports flow into
`AssemblyAttributes.GlobalUsingNamespaces` and resolve only through
`compilation.Assembly`. Existing ambiguity diagnostics are preserved.
- Incrementality: the compilation provider is combined with the
namespace set, so editing usings invalidates the namespace and type
caches. Method-body edits remain cached.
- XamlC: the aggregated-xmlns guard now matches `http:`/`https:` instead
of any CLR namespace starting with `http`, so namespaces such as
`http29708.Controls` resolve.
- Runtime `XamlParser`: the process-wide xmlns cache was filtered by the
first assembly that gathered it, so one assembly's global mappings could
resolve types for another (pre-existing, but more likely now).
Definitions now keep their declaring assembly, and global mappings are
filtered per current assembly in a cached view.
- Docs: `docs/specs/XamlCSharpExpressions.md`.

### Tests
- `SourceGen.UnitTests/GlobalUsingTests.cs`: same-pass generation,
escaped names, exclusions, current-assembly boundary with and without
explicit mappings, extern alias, explicit MAUI default, ambiguity,
edits/rebinding invalidation, deterministic ordering, and no import from
other generators.
- `Xaml.UnitTests/Issues/Maui29708`: Runtime, XamlC, and SourceGen
inflation of a type and markup extension imported through a handwritten
global using plus an MSBuild `<Using>`. A referenced-assembly type is
rejected in Runtime and XamlC.
`RuntimeGlobalMappingsDoNotLeakToOtherAssemblies` fails without the
runtime cache fix.

Validation (macOS, platform TFMs disabled due to a local workload
mismatch):
- `dotnet test
src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj` full
suite: **passed** — 641 passed, 40 skipped. It was run from a copied
output path because `XTypeMultiFileHotReloadTests` fail when the path
contains `~`, independent of this change.
- `dotnet test
src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj
--filter "FullyQualifiedName~Maui29708|FullyQualifiedName~Xmlns"`:
**passed** — 42 passed.
- Full `Controls.Xaml.UnitTests`: 2185 passed, 8 skipped, 2 failed
(`TwoWayDecimalBinding_*`, locale-dependent on the `en_BE` test machine
and unrelated to this change).

### Issues Fixed

Fixes #29708

---------

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Nov 18, 2026
<!-- Please let the below note in for people that find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

### Description of Change

C# namespace `global using` directives now add **current-assembly**
types to the implicit global XAML namespace
(`http://schemas.microsoft.com/dotnet/maui/global`, used when `xmlns` is
omitted).

**Included:** handwritten global usings and MSBuild/SDK-generated ones
(`<Using Include="..." />`).
**Excluded:** namespace/type aliases, extern-alias-qualified imports,
`global using static`, ordinary output of other source generators in the
same pass, and referenced-assembly types (existing explicit
`XmlnsDefinition` mappings can still expose them). Explicit default
namespaces such as `http://schemas.microsoft.com/dotnet/2021/maui` are
unchanged.

Implementation:
- `XamlGenerator`: semantic incremental provider collects active
namespace global usings, normalizes, sorts, and deduplicates them. Emits
`Global.Usings.Xmlns.cs` with `[assembly: XmlnsDefinition(global, ns)]`
(no `AssemblyName`, so Runtime and XamlC resolve against the current
assembly only).
- Same-pass SourceGen resolution: imports flow into
`AssemblyAttributes.GlobalUsingNamespaces` and resolve only through
`compilation.Assembly`. Existing ambiguity diagnostics are preserved.
- Incrementality: the compilation provider is combined with the
namespace set, so editing usings invalidates the namespace and type
caches. Method-body edits remain cached.
- XamlC: the aggregated-xmlns guard now matches `http:`/`https:` instead
of any CLR namespace starting with `http`, so namespaces such as
`http29708.Controls` resolve.
- Runtime `XamlParser`: the process-wide xmlns cache was filtered by the
first assembly that gathered it, so one assembly's global mappings could
resolve types for another (pre-existing, but more likely now).
Definitions now keep their declaring assembly, and global mappings are
filtered per current assembly in a cached view.
- Docs: `docs/specs/XamlCSharpExpressions.md`.

### Tests
- `SourceGen.UnitTests/GlobalUsingTests.cs`: same-pass generation,
escaped names, exclusions, current-assembly boundary with and without
explicit mappings, extern alias, explicit MAUI default, ambiguity,
edits/rebinding invalidation, deterministic ordering, and no import from
other generators.
- `Xaml.UnitTests/Issues/Maui29708`: Runtime, XamlC, and SourceGen
inflation of a type and markup extension imported through a handwritten
global using plus an MSBuild `<Using>`. A referenced-assembly type is
rejected in Runtime and XamlC.
`RuntimeGlobalMappingsDoNotLeakToOtherAssemblies` fails without the
runtime cache fix.

Validation (macOS, platform TFMs disabled due to a local workload
mismatch):
- `dotnet test
src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj` full
suite: **passed** — 641 passed, 40 skipped. It was run from a copied
output path because `XTypeMultiFileHotReloadTests` fail when the path
contains `~`, independent of this change.
- `dotnet test
src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj
--filter "FullyQualifiedName~Maui29708|FullyQualifiedName~Xmlns"`:
**passed** — 42 passed.
- Full `Controls.Xaml.UnitTests`: 2185 passed, 8 skipped, 2 failed
(`TwoWayDecimalBinding_*`, locale-dependent on the `en_BE` test machine
and unrelated to this change).

### Issues Fixed

Fixes #29708

---------

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Nov 18, 2026
<!-- Please let the below note in for people that find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

### Description of Change

C# namespace `global using` directives now add **current-assembly**
types to the implicit global XAML namespace
(`http://schemas.microsoft.com/dotnet/maui/global`, used when `xmlns` is
omitted).

**Included:** handwritten global usings and MSBuild/SDK-generated ones
(`<Using Include="..." />`).
**Excluded:** namespace/type aliases, extern-alias-qualified imports,
`global using static`, ordinary output of other source generators in the
same pass, and referenced-assembly types (existing explicit
`XmlnsDefinition` mappings can still expose them). Explicit default
namespaces such as `http://schemas.microsoft.com/dotnet/2021/maui` are
unchanged.

Implementation:
- `XamlGenerator`: semantic incremental provider collects active
namespace global usings, normalizes, sorts, and deduplicates them. Emits
`Global.Usings.Xmlns.cs` with `[assembly: XmlnsDefinition(global, ns)]`
(no `AssemblyName`, so Runtime and XamlC resolve against the current
assembly only).
- Same-pass SourceGen resolution: imports flow into
`AssemblyAttributes.GlobalUsingNamespaces` and resolve only through
`compilation.Assembly`. Existing ambiguity diagnostics are preserved.
- Incrementality: the compilation provider is combined with the
namespace set, so editing usings invalidates the namespace and type
caches. Method-body edits remain cached.
- XamlC: the aggregated-xmlns guard now matches `http:`/`https:` instead
of any CLR namespace starting with `http`, so namespaces such as
`http29708.Controls` resolve.
- Runtime `XamlParser`: the process-wide xmlns cache was filtered by the
first assembly that gathered it, so one assembly's global mappings could
resolve types for another (pre-existing, but more likely now).
Definitions now keep their declaring assembly, and global mappings are
filtered per current assembly in a cached view.
- Docs: `docs/specs/XamlCSharpExpressions.md`.

### Tests
- `SourceGen.UnitTests/GlobalUsingTests.cs`: same-pass generation,
escaped names, exclusions, current-assembly boundary with and without
explicit mappings, extern alias, explicit MAUI default, ambiguity,
edits/rebinding invalidation, deterministic ordering, and no import from
other generators.
- `Xaml.UnitTests/Issues/Maui29708`: Runtime, XamlC, and SourceGen
inflation of a type and markup extension imported through a handwritten
global using plus an MSBuild `<Using>`. A referenced-assembly type is
rejected in Runtime and XamlC.
`RuntimeGlobalMappingsDoNotLeakToOtherAssemblies` fails without the
runtime cache fix.

Validation (macOS, platform TFMs disabled due to a local workload
mismatch):
- `dotnet test
src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj` full
suite: **passed** — 641 passed, 40 skipped. It was run from a copied
output path because `XTypeMultiFileHotReloadTests` fail when the path
contains `~`, independent of this change.
- `dotnet test
src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj
--filter "FullyQualifiedName~Maui29708|FullyQualifiedName~Xmlns"`:
**passed** — 42 passed.
- Full `Controls.Xaml.UnitTests`: 2185 passed, 8 skipped, 2 failed
(`TwoWayDecimalBinding_*`, locale-dependent on the `en_BE` test machine
and unrelated to this change).

### Issues Fixed

Fixes #29708

---------

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Nov 18, 2026
<!-- Please let the below note in for people that find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

### Description of Change

C# namespace `global using` directives now add **current-assembly**
types to the implicit global XAML namespace
(`http://schemas.microsoft.com/dotnet/maui/global`, used when `xmlns` is
omitted).

**Included:** handwritten global usings and MSBuild/SDK-generated ones
(`<Using Include="..." />`).
**Excluded:** namespace/type aliases, extern-alias-qualified imports,
`global using static`, ordinary output of other source generators in the
same pass, and referenced-assembly types (existing explicit
`XmlnsDefinition` mappings can still expose them). Explicit default
namespaces such as `http://schemas.microsoft.com/dotnet/2021/maui` are
unchanged.

Implementation:
- `XamlGenerator`: semantic incremental provider collects active
namespace global usings, normalizes, sorts, and deduplicates them. Emits
`Global.Usings.Xmlns.cs` with `[assembly: XmlnsDefinition(global, ns)]`
(no `AssemblyName`, so Runtime and XamlC resolve against the current
assembly only).
- Same-pass SourceGen resolution: imports flow into
`AssemblyAttributes.GlobalUsingNamespaces` and resolve only through
`compilation.Assembly`. Existing ambiguity diagnostics are preserved.
- Incrementality: the compilation provider is combined with the
namespace set, so editing usings invalidates the namespace and type
caches. Method-body edits remain cached.
- XamlC: the aggregated-xmlns guard now matches `http:`/`https:` instead
of any CLR namespace starting with `http`, so namespaces such as
`http29708.Controls` resolve.
- Runtime `XamlParser`: the process-wide xmlns cache was filtered by the
first assembly that gathered it, so one assembly's global mappings could
resolve types for another (pre-existing, but more likely now).
Definitions now keep their declaring assembly, and global mappings are
filtered per current assembly in a cached view.
- Docs: `docs/specs/XamlCSharpExpressions.md`.

### Tests
- `SourceGen.UnitTests/GlobalUsingTests.cs`: same-pass generation,
escaped names, exclusions, current-assembly boundary with and without
explicit mappings, extern alias, explicit MAUI default, ambiguity,
edits/rebinding invalidation, deterministic ordering, and no import from
other generators.
- `Xaml.UnitTests/Issues/Maui29708`: Runtime, XamlC, and SourceGen
inflation of a type and markup extension imported through a handwritten
global using plus an MSBuild `<Using>`. A referenced-assembly type is
rejected in Runtime and XamlC.
`RuntimeGlobalMappingsDoNotLeakToOtherAssemblies` fails without the
runtime cache fix.

Validation (macOS, platform TFMs disabled due to a local workload
mismatch):
- `dotnet test
src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj` full
suite: **passed** — 641 passed, 40 skipped. It was run from a copied
output path because `XTypeMultiFileHotReloadTests` fail when the path
contains `~`, independent of this change.
- `dotnet test
src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj
--filter "FullyQualifiedName~Maui29708|FullyQualifiedName~Xmlns"`:
**passed** — 42 passed.
- Full `Controls.Xaml.UnitTests`: 2185 passed, 8 skipped, 2 failed
(`TwoWayDecimalBinding_*`, locale-dependent on the `en_BE` test machine
and unrelated to this change).

### Issues Fixed

Fixes #29708

---------

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Nov 19, 2026
<!-- Please let the below note in for people that find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

### Description of Change

C# namespace `global using` directives now add **current-assembly**
types to the implicit global XAML namespace
(`http://schemas.microsoft.com/dotnet/maui/global`, used when `xmlns` is
omitted).

**Included:** handwritten global usings and MSBuild/SDK-generated ones
(`<Using Include="..." />`).
**Excluded:** namespace/type aliases, extern-alias-qualified imports,
`global using static`, ordinary output of other source generators in the
same pass, and referenced-assembly types (existing explicit
`XmlnsDefinition` mappings can still expose them). Explicit default
namespaces such as `http://schemas.microsoft.com/dotnet/2021/maui` are
unchanged.

Implementation:
- `XamlGenerator`: semantic incremental provider collects active
namespace global usings, normalizes, sorts, and deduplicates them. Emits
`Global.Usings.Xmlns.cs` with `[assembly: XmlnsDefinition(global, ns)]`
(no `AssemblyName`, so Runtime and XamlC resolve against the current
assembly only).
- Same-pass SourceGen resolution: imports flow into
`AssemblyAttributes.GlobalUsingNamespaces` and resolve only through
`compilation.Assembly`. Existing ambiguity diagnostics are preserved.
- Incrementality: the compilation provider is combined with the
namespace set, so editing usings invalidates the namespace and type
caches. Method-body edits remain cached.
- XamlC: the aggregated-xmlns guard now matches `http:`/`https:` instead
of any CLR namespace starting with `http`, so namespaces such as
`http29708.Controls` resolve.
- Runtime `XamlParser`: the process-wide xmlns cache was filtered by the
first assembly that gathered it, so one assembly's global mappings could
resolve types for another (pre-existing, but more likely now).
Definitions now keep their declaring assembly, and global mappings are
filtered per current assembly in a cached view.
- Docs: `docs/specs/XamlCSharpExpressions.md`.

### Tests
- `SourceGen.UnitTests/GlobalUsingTests.cs`: same-pass generation,
escaped names, exclusions, current-assembly boundary with and without
explicit mappings, extern alias, explicit MAUI default, ambiguity,
edits/rebinding invalidation, deterministic ordering, and no import from
other generators.
- `Xaml.UnitTests/Issues/Maui29708`: Runtime, XamlC, and SourceGen
inflation of a type and markup extension imported through a handwritten
global using plus an MSBuild `<Using>`. A referenced-assembly type is
rejected in Runtime and XamlC.
`RuntimeGlobalMappingsDoNotLeakToOtherAssemblies` fails without the
runtime cache fix.

Validation (macOS, platform TFMs disabled due to a local workload
mismatch):
- `dotnet test
src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj` full
suite: **passed** — 641 passed, 40 skipped. It was run from a copied
output path because `XTypeMultiFileHotReloadTests` fail when the path
contains `~`, independent of this change.
- `dotnet test
src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj
--filter "FullyQualifiedName~Maui29708|FullyQualifiedName~Xmlns"`:
**passed** — 42 passed.
- Full `Controls.Xaml.UnitTests`: 2185 passed, 8 skipped, 2 failed
(`TwoWayDecimalBinding_*`, locale-dependent on the `en_BE` test machine
and unrelated to this change).

### Issues Fixed

Fixes #29708

---------

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Nov 22, 2026
<!-- Please let the below note in for people that find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

### Description of Change

C# namespace `global using` directives now add **current-assembly**
types to the implicit global XAML namespace
(`http://schemas.microsoft.com/dotnet/maui/global`, used when `xmlns` is
omitted).

**Included:** handwritten global usings and MSBuild/SDK-generated ones
(`<Using Include="..." />`).
**Excluded:** namespace/type aliases, extern-alias-qualified imports,
`global using static`, ordinary output of other source generators in the
same pass, and referenced-assembly types (existing explicit
`XmlnsDefinition` mappings can still expose them). Explicit default
namespaces such as `http://schemas.microsoft.com/dotnet/2021/maui` are
unchanged.

Implementation:
- `XamlGenerator`: semantic incremental provider collects active
namespace global usings, normalizes, sorts, and deduplicates them. Emits
`Global.Usings.Xmlns.cs` with `[assembly: XmlnsDefinition(global, ns)]`
(no `AssemblyName`, so Runtime and XamlC resolve against the current
assembly only).
- Same-pass SourceGen resolution: imports flow into
`AssemblyAttributes.GlobalUsingNamespaces` and resolve only through
`compilation.Assembly`. Existing ambiguity diagnostics are preserved.
- Incrementality: the compilation provider is combined with the
namespace set, so editing usings invalidates the namespace and type
caches. Method-body edits remain cached.
- XamlC: the aggregated-xmlns guard now matches `http:`/`https:` instead
of any CLR namespace starting with `http`, so namespaces such as
`http29708.Controls` resolve.
- Runtime `XamlParser`: the process-wide xmlns cache was filtered by the
first assembly that gathered it, so one assembly's global mappings could
resolve types for another (pre-existing, but more likely now).
Definitions now keep their declaring assembly, and global mappings are
filtered per current assembly in a cached view.
- Docs: `docs/specs/XamlCSharpExpressions.md`.

### Tests
- `SourceGen.UnitTests/GlobalUsingTests.cs`: same-pass generation,
escaped names, exclusions, current-assembly boundary with and without
explicit mappings, extern alias, explicit MAUI default, ambiguity,
edits/rebinding invalidation, deterministic ordering, and no import from
other generators.
- `Xaml.UnitTests/Issues/Maui29708`: Runtime, XamlC, and SourceGen
inflation of a type and markup extension imported through a handwritten
global using plus an MSBuild `<Using>`. A referenced-assembly type is
rejected in Runtime and XamlC.
`RuntimeGlobalMappingsDoNotLeakToOtherAssemblies` fails without the
runtime cache fix.

Validation (macOS, platform TFMs disabled due to a local workload
mismatch):
- `dotnet test
src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj` full
suite: **passed** — 641 passed, 40 skipped. It was run from a copied
output path because `XTypeMultiFileHotReloadTests` fail when the path
contains `~`, independent of this change.
- `dotnet test
src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj
--filter "FullyQualifiedName~Maui29708|FullyQualifiedName~Xmlns"`:
**passed** — 42 passed.
- Full `Controls.Xaml.UnitTests`: 2185 passed, 8 skipped, 2 failed
(`TwoWayDecimalBinding_*`, locale-dependent on the `en_BE` test machine
and unrelated to this change).

### Issues Fixed

Fixes #29708

---------

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Nov 23, 2026
<!-- Please let the below note in for people that find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

### Description of Change

C# namespace `global using` directives now add **current-assembly**
types to the implicit global XAML namespace
(`http://schemas.microsoft.com/dotnet/maui/global`, used when `xmlns` is
omitted).

**Included:** handwritten global usings and MSBuild/SDK-generated ones
(`<Using Include="..." />`).
**Excluded:** namespace/type aliases, extern-alias-qualified imports,
`global using static`, ordinary output of other source generators in the
same pass, and referenced-assembly types (existing explicit
`XmlnsDefinition` mappings can still expose them). Explicit default
namespaces such as `http://schemas.microsoft.com/dotnet/2021/maui` are
unchanged.

Implementation:
- `XamlGenerator`: semantic incremental provider collects active
namespace global usings, normalizes, sorts, and deduplicates them. Emits
`Global.Usings.Xmlns.cs` with `[assembly: XmlnsDefinition(global, ns)]`
(no `AssemblyName`, so Runtime and XamlC resolve against the current
assembly only).
- Same-pass SourceGen resolution: imports flow into
`AssemblyAttributes.GlobalUsingNamespaces` and resolve only through
`compilation.Assembly`. Existing ambiguity diagnostics are preserved.
- Incrementality: the compilation provider is combined with the
namespace set, so editing usings invalidates the namespace and type
caches. Method-body edits remain cached.
- XamlC: the aggregated-xmlns guard now matches `http:`/`https:` instead
of any CLR namespace starting with `http`, so namespaces such as
`http29708.Controls` resolve.
- Runtime `XamlParser`: the process-wide xmlns cache was filtered by the
first assembly that gathered it, so one assembly's global mappings could
resolve types for another (pre-existing, but more likely now).
Definitions now keep their declaring assembly, and global mappings are
filtered per current assembly in a cached view.
- Docs: `docs/specs/XamlCSharpExpressions.md`.

### Tests
- `SourceGen.UnitTests/GlobalUsingTests.cs`: same-pass generation,
escaped names, exclusions, current-assembly boundary with and without
explicit mappings, extern alias, explicit MAUI default, ambiguity,
edits/rebinding invalidation, deterministic ordering, and no import from
other generators.
- `Xaml.UnitTests/Issues/Maui29708`: Runtime, XamlC, and SourceGen
inflation of a type and markup extension imported through a handwritten
global using plus an MSBuild `<Using>`. A referenced-assembly type is
rejected in Runtime and XamlC.
`RuntimeGlobalMappingsDoNotLeakToOtherAssemblies` fails without the
runtime cache fix.

Validation (macOS, platform TFMs disabled due to a local workload
mismatch):
- `dotnet test
src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj` full
suite: **passed** — 641 passed, 40 skipped. It was run from a copied
output path because `XTypeMultiFileHotReloadTests` fail when the path
contains `~`, independent of this change.
- `dotnet test
src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj
--filter "FullyQualifiedName~Maui29708|FullyQualifiedName~Xmlns"`:
**passed** — 42 passed.
- Full `Controls.Xaml.UnitTests`: 2185 passed, 8 skipped, 2 failed
(`TwoWayDecimalBinding_*`, locale-dependent on the `en_BE` test machine
and unrelated to this change).

### Issues Fixed

Fixes #29708

---------

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@kubaflo kubaflo added this to the .NET 11 SR2 milestone Nov 24, 2026
KarthikRajaKalaimani pushed a commit to KarthikRajaKalaimani/maui that referenced this pull request Nov 26, 2026
<!-- Please let the below note in for people that find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
Open .NET 11 fix PRs against net11 for review; target main for
next-major features.
After approval, a maintainer manually retargets the fix PR to the active
inflight
branch and merges it directly there. Do not merge individual fixes into
net11.
Bots must not retarget or merge. Candidate integration into net11 and
release/*
changes are separate, explicitly coordinated release work.
-->

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

### Description of Change

Revert dotnet#39839 on `main` as requested. This restores the previous
behavior: a `Style` cannot override the default
`Shell.FlyoutBackgroundColor` binding until the candidate fix is
forwarded to `main`.

The identical implementation and regression tests are already on
`candidate/11.0.1xx-sr2`, where they were included in dotnet#40170 (commit
`706b461e9296fd30f7ff3c057dacf2025d60a698`). A separate candidate PR for
the same patch would be empty, so this PR changes only `main`.

### Validation

- Verified the commit is the exact inverse of
`9291bfb20edde2cc822b8e2a110f63d2b3425e09`; both changed files match
their pre-fix blobs.
- `dotnet build Microsoft.Maui.BuildTasks.slnf -c Debug
-p:IncludeIosTargetFrameworks=false
-p:IncludeAndroidTargetFrameworks=false
-p:IncludeMacCatalystTargetFrameworks=false
-p:IncludeWindowsTargetFrameworks=false
-p:IncludeTizenTargetFrameworks=false -p:TreatWarningsAsErrors=false
--verbosity quiet` — passed.
- `dotnet test
src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj
--no-restore -c Debug -p:IncludeIosTargetFrameworks=false
-p:IncludeAndroidTargetFrameworks=false
-p:IncludeMacCatalystTargetFrameworks=false
-p:IncludeWindowsTargetFrameworks=false
-p:IncludeTizenTargetFrameworks=false -p:TreatWarningsAsErrors=false
--filter 'FullyQualifiedName~AppThemeTests' --verbosity quiet` — passed:
15 tests before the revert and 13 after removal of the two reverted
tests.
- `dotnet test
src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj
--no-build --no-restore -c Debug -p:IncludeIosTargetFrameworks=false
-p:IncludeAndroidTargetFrameworks=false
-p:IncludeMacCatalystTargetFrameworks=false
-p:IncludeWindowsTargetFrameworks=false
-p:IncludeTizenTargetFrameworks=false -p:TreatWarningsAsErrors=false
--filter 'FullyQualifiedName~ShellTests|FullyQualifiedName~StyleTests'
--verbosity quiet` — passed: 147 tests.
- With the two original regression tests temporarily retained against
the reverted implementation, `dotnet test
src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj
--no-restore -c Debug -p:IncludeIosTargetFrameworks=false
-p:IncludeAndroidTargetFrameworks=false
-p:IncludeMacCatalystTargetFrameworks=false
-p:IncludeWindowsTargetFrameworks=false
-p:IncludeTizenTargetFrameworks=false -p:TreatWarningsAsErrors=false
--filter
'FullyQualifiedName~StyleSetsShellFlyoutBackgroundColor|FullyQualifiedName~ShellFlyoutBackgroundColorFollowsTheThemeWithoutAStyle'
--logger 'console;verbosity=normal'` — expected failure: the style test
received white instead of red; the default-theme test passed. The
temporarily retained tests were removed again before committing.
- The combined selection `dotnet test
src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj
--no-restore -c Debug -p:IncludeIosTargetFrameworks=false
-p:IncludeAndroidTargetFrameworks=false
-p:IncludeMacCatalystTargetFrameworks=false
-p:IncludeWindowsTargetFrameworks=false
-p:IncludeTizenTargetFrameworks=false -p:TreatWarningsAsErrors=false
--filter
'FullyQualifiedName~AppThemeTests|FullyQualifiedName~ShellTests|FullyQualifiedName~StyleTests'
--verbosity quiet` failed
`CorrectDefaultRadioButtonThemeColorsInLightAndDarkModes` (159 passed, 1
failed). The same failure occurred with the original patch restored on
the unmodified `main` baseline (161 passed, 1 failed); the isolated
selections above pass.
- `dotnet format Microsoft.Maui.sln --no-restore --verify-no-changes
--include src/Controls/src/Core/Shell/Shell.cs
src/Controls/tests/Core.UnitTests/AppThemeTests.cs --exclude
Templates/src --exclude-diagnostics CA1822 --verbosity quiet` — passed.

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Related to dotnet#9736; this revert intentionally restores the issue on
`main`.

<!--
Verify the target branch follows the release workflow in
docs/ReleaseBranchWorkflow.md.
Infrastructure and documentation changes should target the branch where
they apply.
-->

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
KarthikRajaKalaimani pushed a commit to KarthikRajaKalaimani/maui that referenced this pull request Nov 26, 2026
…0170)

<!-- Please let the below note in for people that find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

### Description of Change

C# namespace `global using` directives now add **current-assembly**
types to the implicit global XAML namespace
(`http://schemas.microsoft.com/dotnet/maui/global`, used when `xmlns` is
omitted).

**Included:** handwritten global usings and MSBuild/SDK-generated ones
(`<Using Include="..." />`).
**Excluded:** namespace/type aliases, extern-alias-qualified imports,
`global using static`, ordinary output of other source generators in the
same pass, and referenced-assembly types (existing explicit
`XmlnsDefinition` mappings can still expose them). Explicit default
namespaces such as `http://schemas.microsoft.com/dotnet/2021/maui` are
unchanged.

Implementation:
- `XamlGenerator`: semantic incremental provider collects active
namespace global usings, normalizes, sorts, and deduplicates them. Emits
`Global.Usings.Xmlns.cs` with `[assembly: XmlnsDefinition(global, ns)]`
(no `AssemblyName`, so Runtime and XamlC resolve against the current
assembly only).
- Same-pass SourceGen resolution: imports flow into
`AssemblyAttributes.GlobalUsingNamespaces` and resolve only through
`compilation.Assembly`. Existing ambiguity diagnostics are preserved.
- Incrementality: the compilation provider is combined with the
namespace set, so editing usings invalidates the namespace and type
caches. Method-body edits remain cached.
- XamlC: the aggregated-xmlns guard now matches `http:`/`https:` instead
of any CLR namespace starting with `http`, so namespaces such as
`http29708.Controls` resolve.
- Runtime `XamlParser`: the process-wide xmlns cache was filtered by the
first assembly that gathered it, so one assembly's global mappings could
resolve types for another (pre-existing, but more likely now).
Definitions now keep their declaring assembly, and global mappings are
filtered per current assembly in a cached view.
- Docs: `docs/specs/XamlCSharpExpressions.md`.

### Tests
- `SourceGen.UnitTests/GlobalUsingTests.cs`: same-pass generation,
escaped names, exclusions, current-assembly boundary with and without
explicit mappings, extern alias, explicit MAUI default, ambiguity,
edits/rebinding invalidation, deterministic ordering, and no import from
other generators.
- `Xaml.UnitTests/Issues/Maui29708`: Runtime, XamlC, and SourceGen
inflation of a type and markup extension imported through a handwritten
global using plus an MSBuild `<Using>`. A referenced-assembly type is
rejected in Runtime and XamlC.
`RuntimeGlobalMappingsDoNotLeakToOtherAssemblies` fails without the
runtime cache fix.

Validation (macOS, platform TFMs disabled due to a local workload
mismatch):
- `dotnet test
src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj` full
suite: **passed** — 641 passed, 40 skipped. It was run from a copied
output path because `XTypeMultiFileHotReloadTests` fail when the path
contains `~`, independent of this change.
- `dotnet test
src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj
--filter "FullyQualifiedName~Maui29708|FullyQualifiedName~Xmlns"`:
**passed** — 42 passed.
- Full `Controls.Xaml.UnitTests`: 2185 passed, 8 skipped, 2 failed
(`TwoWayDecimalBinding_*`, locale-dependent on the `en_BE` test machine
and unrelated to this change).

### Issues Fixed

Fixes dotnet#29708

---------

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

auto generate global xmlns from c# global usings

5 participants