Skip to content

refactor(xaml)!: Remove clr-namespace: XAML leniency (BC42) - #23928

Open
Xiaoy312 wants to merge 5 commits into
feature/breakingchangesfrom
dev/xygu/20260730/bc42-remove-clr-namespace-leniency
Open

refactor(xaml)!: Remove clr-namespace: XAML leniency (BC42)#23928
Xiaoy312 wants to merge 5 commits into
feature/breakingchangesfrom
dev/xygu/20260730/bc42-remove-clr-namespace-leniency

Conversation

@Xiaoy312

Copy link
Copy Markdown
Contributor

GitHub Issue: closes #

PR Type:

🔄 Refactoring (no functional changes, no api changes)

What changed? 🚀

BC42 — remove the clr-namespace: XAML leniency.

WinUI/UWP only supports the using:MyApp.Controls xmlns form. Uno additionally accepted the
WPF/Silverlight clr-namespace:MyApp.Controls;assembly=MyLib form, silently stripping the prefix
and the ;assembly= token before resolving types. That let non-portable XAML build on Uno and then
fail when the same markup was compiled for WinAppSDK.

The declaration is now rejected outright, with no deprecation cycle:

  • Build time — the new UXAML0006 diagnostic, reported with the file and line of the
    declaration.
  • Run timeXamlReader.Load (and therefore Hot Reload) throws a XamlParseException.

The only exemption is a prefix listed in mc:Ignorable on the root element.

Notable implementation details

  • The check fires on the declaration, not on first use. A clr-namespace: xmlns is invalid
    WinUI markup whether or not the prefix is referenced, and rejecting at the declaration gives an
    actionable message from a single choke point per parser instead of threading diagnostic locations
    through four resolution call sites.
  • Validation is deferred to the end of the parse. The XAML reader yields NamespaceDeclaration
    nodes before it reads the element's mc:Ignorable attribute, so declarations are collected
    during the visit and reported once the ignorable set is known.
  • Simply deleting the stripping would not have been a hard error. Unresolved prefixed types fall
    through to SearchWithFuzzyMatching, which can still resolve by simple name — and fuzzy matching
    is enabled in XamlGenerationTests. An explicit diagnostic is required.
  • Conditional-XAML prefixes are deliberately not exempt (e.g. xmlns:android="clr-namespace:…").
    On the included platform IsIncluded already rewrites the URI to the presentation namespace,
    discarding the CLR namespace; on the excluded platform the elements are dropped. That markup never
    did what its author intended, so the error is a true positive.
  • src/SourceGenerators/System.Xaml/ is untouched. Its clr-namespace: handling is already
    unreachable on Uno's paths (both entry points construct XamlSchemaContext with an empty assembly
    list, which gates ResolveXamlTypeName off). Uno.Xaml.Tests stays green.
  • Repo XAML migrated to using:. Only two files actually used the prefix; the rest declared one they
    never referenced. themeresources_v2.xaml is generated by FluentMerge.targets and was
    regenerated, not hand-edited.

Validation

Result
Compile — Uno.UI-UnitTests-only.slnf 0 errors
Compile — SamplesApp.Skia.Generic (Debug + Release) 0 errors
Test — Uno.Xaml.Tests (vendored parser) 791 total, 0 failed
Test — Uno.UI.SourceGenerators.Tests 479 total, 0 failed (4 new UXAML0006 cases)
Test — Uno.UI.UnitTests 4036 total, 13 failed — all pre-existing timezone-dependent Windows_Globalization Calendar tests, unrelated
Runtime — Given_XamlReader, Skia Desktop 54/54 passed, including both new cases

Fails-before / passes-after: with the two runtime files stashed and rebuilt, the two rejection
tests fail and the mc:Ignorable test still passes; with the change applied all three pass.

Test coverage spans a used prefix, an unused prefix, an inline-scope declaration (xmlns on an element
inside a member, e.g. a DataTemplate), and an mc:Ignorable prefix that must keep working.

PR Checklist ✅

Breaking change — impact and migration path

This is an intentional breaking change, part of the 7.0 breaking-change rollup (Phase 5), targeting
the feature/breakingchanges branch.

Impact: any app or library whose XAML declares a clr-namespace: xmlns now fails to build with
UXAML0006, and fails at run time if the markup reaches XamlReader.Load. Unused declarations are
rejected too.

Migration:

- xmlns:local="clr-namespace:MyApp.Controls;assembly=MyLib"
+ xmlns:local="using:MyApp.Controls"

The assembly is inferred from the compilation, so the ;assembly= token has no replacement — drop
it. Prefixes listed in mc:Ignorable on the root element are unaffected.

Documented in doc/articles/migrating-to-uno-7.md (new XAML changes section plus a migration
checklist step) and doc/articles/uno-build-error-codes.md (UXAML0006).

🤖 Generated with Claude Code

Xiaoy312 and others added 5 commits July 30, 2026 20:02
WinUI only supports the `using:` xmlns form. Uno also accepted the
WPF-style `clr-namespace:Ns;assembly=Asm` and silently stripped it, which
let non-portable XAML build on Uno but fail on WinAppSDK.

The declaration is now rejected outright — at build time with the new
`UXAML0006` diagnostic, and at run time by `XamlReader` with a
`XamlParseException`. Prefixes listed in the root `mc:Ignorable` stay
exempt. Validation is deferred to the end of the parse because the reader
yields namespace nodes before it reads `mc:Ignorable`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Two files actually used their `clr-namespace:` prefix — CalendarView
theme resources (converted) and the markup-extension generation fixture
(folded into the `local:` prefix, which already pointed at the same CLR
namespace). The rest declared a prefix they never referenced.

`themeresources_v2.xaml` is generated by FluentMerge.targets and is
regenerated here, not hand-edited.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Generator tests assert `UXAML0006` for a used and an unused prefix, and
that an `mc:Ignorable` prefix stays accepted. XamlReader tests cover the
same three cases at run time.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Adds a XAML changes section to the 7.0 migration guide, documents
`UXAML0006`, and drops the auto-codebehind claim that `clr-namespace:`
root elements are supported.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The declaration collected from `VisitMember` (an xmlns declared on an
element inside a member, e.g. a `DataTemplate`) had no coverage. It
reports the attribute column exactly, unlike the root-element case.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added area/code-generation Categorizes an issue or PR as relevant to code generation area/automation Categorizes an issue or PR as relevant to project automation kind/documentation labels Jul 31, 2026
@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-23928/docs/index.html

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 225135 found UI Test snapshots differences: skia-linux-screenshots: 88, skia-windows-screenshots: 99

Details
  • skia-linux-screenshots: 88 changed over 2392

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • CalendarView_Theming.png
    • EllipsemaskingEllipseGrid.png
    • Examples.png
    • ImageSourceUrlMsAppDataScheme.png
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • DisplayInformation.png-dark
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_CurrentReading.png
    • Image_UseTargetSizeLate.png-dark
    • Image_UseTargetSizeLate.png
    • Basics Pivot Test.png
    • Buttons.png
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • DoubleImageBrushInList.png-dark
    • DoubleImageBrushInList.png
    • ExpanderColorValidationPage.png-dark
  • skia-windows-screenshots: 99 changed over 2392

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ColorPickerSample.png-dark
    • DisplayInformation.png-dark
    • DisplayInformation.png
    • Gamepad_Enumeration.png-dark
    • Buttons.png-dark
    • Buttons.png
    • ContextRequested.png-dark
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • ClipboardTests.png
    • Focus_FocusVisual_Properties.png-dark
    • CalendarView_Theming.png-dark
    • DropDownButtonPage.png-dark
    • DropDownButtonPage.png
    • Examples.png
    • ExpanderColorValidationPage.png-dark
    • ImageBrushInList.png-dark
    • ImageBrushInList.png

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 225135 has failed on Uno.UI - CI.

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

Labels

area/automation Categorizes an issue or PR as relevant to project automation area/code-generation Categorizes an issue or PR as relevant to code generation kind/documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants