refactor(xaml)!: Remove clr-namespace: XAML leniency (BC42) - #23928
Open
Xiaoy312 wants to merge 5 commits into
Open
refactor(xaml)!: Remove clr-namespace: XAML leniency (BC42)#23928Xiaoy312 wants to merge 5 commits into
clr-namespace: XAML leniency (BC42)#23928Xiaoy312 wants to merge 5 commits into
Conversation
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>
Contributor
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-23928/docs/index.html |
Contributor
|
The build 225135 found UI Test snapshots differences: Details
|
Contributor
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.Controlsxmlns form. Uno additionally accepted theWPF/Silverlight
clr-namespace:MyApp.Controls;assembly=MyLibform, silently stripping the prefixand the
;assembly=token before resolving types. That let non-portable XAML build on Uno and thenfail when the same markup was compiled for WinAppSDK.
The declaration is now rejected outright, with no deprecation cycle:
UXAML0006diagnostic, reported with the file and line of thedeclaration.
XamlReader.Load(and therefore Hot Reload) throws aXamlParseException.The only exemption is a prefix listed in
mc:Ignorableon the root element.Notable implementation details
clr-namespace:xmlns is invalidWinUI 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.
NamespaceDeclarationnodes before it reads the element's
mc:Ignorableattribute, so declarations are collectedduring the visit and reported once the ignorable set is known.
through to
SearchWithFuzzyMatching, which can still resolve by simple name — and fuzzy matchingis enabled in
XamlGenerationTests. An explicit diagnostic is required.xmlns:android="clr-namespace:…").On the included platform
IsIncludedalready 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. Itsclr-namespace:handling is alreadyunreachable on Uno's paths (both entry points construct
XamlSchemaContextwith an empty assemblylist, which gates
ResolveXamlTypeNameoff).Uno.Xaml.Testsstays green.using:. Only two files actually used the prefix; the rest declared one theynever referenced.
themeresources_v2.xamlis generated byFluentMerge.targetsand wasregenerated, not hand-edited.
Validation
Uno.UI-UnitTests-only.slnfSamplesApp.Skia.Generic(Debug + Release)Uno.Xaml.Tests(vendored parser)Uno.UI.SourceGenerators.TestsUXAML0006cases)Uno.UI.UnitTestsWindows_GlobalizationCalendar tests, unrelatedGiven_XamlReader, Skia DesktopFails-before / passes-after: with the two runtime files stashed and rebuilt, the two rejection
tests fail and the
mc:Ignorabletest 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 anmc:Ignorableprefix that must keep working.PR Checklist ✅
Screenshots Compare Test Runresults.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/breakingchangesbranch.Impact: any app or library whose XAML declares a
clr-namespace:xmlns now fails to build withUXAML0006, and fails at run time if the markup reachesXamlReader.Load. Unused declarations arerejected too.
Migration:
The assembly is inferred from the compilation, so the
;assembly=token has no replacement — dropit. Prefixes listed in
mc:Ignorableon the root element are unaffected.Documented in
doc/articles/migrating-to-uno-7.md(new XAML changes section plus a migrationchecklist step) and
doc/articles/uno-build-error-codes.md(UXAML0006).🤖 Generated with Claude Code