Skip to content

[net11.0] Support C# 14 extension properties in XAML SourceGen - #32898

Merged
kubaflo merged 20 commits into
candidate/11.0.1xx-sr2from
feature/csharp14-extension-properties-xaml
Nov 17, 2026
Merged

kubaflo merged 20 commits into
candidate/11.0.1xx-sr2from
feature/csharp14-extension-properties-xaml

Conversation

@StephaneDelcroix

@StephaneDelcroix StephaneDelcroix commented Nov 27, 2025 •

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!

Description of Change

Adds C# 14 extension-property assignment to the XAML source generator.

Extension properties can be used without qualification when their container is in the element's effective default XAML namespace:

[assembly: XmlnsDefinition(
	"http://schemas.microsoft.com/dotnet/2021/maui",
	"MyApp.Extensions")]

namespace MyApp.Extensions;

public static class LabelExtensions
{
	extension(Label label)
	{
		public string MyTag { get; set; }
	}
}
<Label MyTag="hello" />

Containers introduced through MAUI's global XML namespace are also available to XAML documents using that namespace. Explicit qualification remains available for selection and disambiguation:

<Label local:LabelExtensions.MyTag="hello" />

Resolution rules

  • Ordinary events, BindableProperties, and instance properties retain precedence over extension properties.
  • Unqualified extension properties are discovered only in CLR namespaces mapped from the element's effective default xmlns; no global assembly scan is performed.
  • The container must be a non-generic static class containing a compiler-generated C# extension declaration.
  • Only the compiler-emitted setter of an actual extension property declaration is called (matching receiver and value type); a hand-written static set_Name method is never treated as an accessor.
  • An accessible instance property or field hides extension properties of the same name even when it cannot be assigned, as in C# (explicitly implemented interface properties hide nothing).
  • An [XmlnsDefinition] only brings its namespace in from the assembly it names.
  • All applicable setters of all in-scope containers compete together; the unique most-specific receiver wins, independent of declaration or metadata order.
  • Equal or unrelated applicable candidates produce MAUIX2021, including when the ambiguity is inside one container.
  • An explicitly named extension container that does not define the requested property produces MAUIX2020 and cannot fall through to an unrelated target property.
  • Values can come from markup extensions such as {StaticResource}, and the extension property's own [TypeConverter] is honoured.

Support matrix

Inflator Support
SourceGen Supported: unqualified namespace-scoped and explicitly qualified assignment
XamlC Not supported
Runtime XAML inflation Not supported

XamlC and Runtime retain their existing unresolved-member behavior. Their product code is unchanged by this PR.

Direct binding paths such as {Binding Person.FullName} remain out of scope. Extension properties are static accessors rather than reflected instance properties and do not define change-notification semantics.

Tests

SourceGen coverage includes:

  • Default-namespace and global-namespace lookup.
  • Cross-assembly namespace mappings.
  • Instance-property precedence.
  • Most-specific receiver selection across two and three containers, in different declaration orders.
  • Ambiguous candidates and out-of-scope containers.
  • Explicit qualification and disambiguation.
  • Handwritten lookalike accessor rejection.
  • Qualified property-element compatibility, including <ContentView.Resources> on a ContentPage.
  • {StaticResource} values, hand-written set_Name lookalikes, ambiguity inside one container, unassignable and explicitly implemented instance members, and containers from an unmapped assembly sharing a mapped namespace.

Validation after rebasing on main (macOS):

  • dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj --filter FullyQualifiedName~ExtensionProperties: 19 passed. The 5 new regression tests fail on the previous generator.
  • dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj: 2,198 passed, 8 skipped, 2 failed (TwoWayDecimalBinding_INPC/_VMToUI, locale-dependent decimal parsing in CSharpExpressions, unrelated to this PR).
  • dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj: 628 passed, 40 skipped.

Issues Fixed

None (new feature).

@kubaflo

kubaflo commented May 24, 2026

Copy link
Copy Markdown
Contributor

/review -b feature/refactor-copilot-yml

@MauiBot

This comment has been minimized.

@kubaflo

kubaflo commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

/review -b feature/enhanced-reviewer -p windows

@MauiBot

This comment has been minimized.

@kubaflo kubaflo 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.

Can you please resolve conflicts?

@kubaflo kubaflo added the do-not-merge Don't merge this PR label Aug 24, 2026
@kubaflo kubaflo changed the title Add C# 14 extension property support for XAML [net12.0]Add C# 14 extension property support for XAML Aug 24, 2026
@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 Aug 30, 2026
@MauiBot

This comment has been minimized.

@MauiBot MauiBot removed the s/agent-review-in-progress AI review is currently running for this PR label Aug 30, 2026
@StephaneDelcroix
StephaneDelcroix force-pushed the feature/csharp14-extension-properties-xaml branch from 77b97ce to 0b3282f Compare August 31, 2026 12:25
@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 -- 32898

Or

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

@StephaneDelcroix StephaneDelcroix changed the title [net12.0]Add C# 14 extension property support for XAML [net11.0] Support C# 14 extension properties in XAML with qualified syntax Sep 7, 2026
@kubaflo

This comment has been minimized.

@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.

🟡 Changes recommended

A critical setter-resolution flaw can invoke a handwritten lookalike instead of rejecting a private setter, while property-resolution, resource-conversion, and Hot Reload regressions also remain unresolved.

9 open issues
1 file not reviewed
  • src/Controls/src/SourceGen/xlf/MauiGResources.Designer.cs: Generated file

Review effort: Balanced

{
if (!method.IsStatic || method.DeclaredAccessibility != Accessibility.Public || method.IsGenericMethod)
continue;
if (!method.ReturnsVoid || method.Parameters.Length != 2 || method.Parameters[0].RefKind != RefKind.None)
Comment on lines +94 to +96
if (!asCollectionItem && !attached && !hasBindableProperty && CanSetScopedExtensionProperty(parentVar, propertyName, valueNode, context, out var scopedAccessors, out scopedReported))
{
SetExtensionProperty(writer, parentVar, scopedAccessors!, valueNode, context, getNodeValue);
Comment on lines +720 to +722
static IPropertySymbol? GetInstanceProperty(ITypeSymbol targetType, string name, SourceGenContext context)
=> targetType.GetAllProperties(name, context)
.FirstOrDefault(property => targetType.TypeKind == TypeKind.Interface || property.ContainingType.TypeKind != TypeKind.Interface);
ambiguous = false;

//unprefixed attributes carry no namespace, the scope is the default xmlns declared for the element
if (propertyName.NamespaceURI != string.Empty || node.NamespaceResolver == null)
Comment on lines +1777 to +1780
return localVar.Type.InheritsFrom(propertyType, context)
|| (propertyType.IsInterface() && localVar.Type.Implements(propertyType))
|| propertyType.Equals(context.Compilation.ObjectType, SymbolEqualityComparer.Default)
|| context.Compilation.HasImplicitConversion(localVar.Type, propertyType)
@MauiBot

This comment has been minimized.

@MauiBot MauiBot added s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix) and removed s/agent-gate-failed AI could not verify tests catch the bug s/agent-review-in-progress AI review is currently running for this PR labels Nov 16, 2026
@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 16, 2026
@MauiBot

MauiBot commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

PR Test Gate

@StephaneDelcroix — existing-test verification for commit 368d7276.

Result PASSED Platform Android Commit 368d7276


🧪 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
ExtensionPropertyMetadataTests ✅ Failed as expected (77s) ✅ Passed (27s)
📄 XAML unit tests
Test group Without fix With fix
GlobalScopedExtensionProperties ✅ Failed as expected (78s) ✅ Passed (31s)
ScopedExtensionProperties ✅ Failed as expected (38s) ✅ Passed (37s)
ScopedExtensionPropertiesErrors ✅ Failed as expected (30s) ✅ Passed (38s)
ScopedExtensionPropertiesLeaked ✅ Failed as expected (30s) ✅ Passed (42s)
ScopedExtensionPropertiesLookalike ✅ Failed as expected (29s) ✅ Passed (40s)
ScopedExtensionPropertiesNestedAmbiguity ✅ Failed as expected (30s) ✅ Passed (44s)
ScopedExtensionPropertiesOutOfScope ✅ Failed as expected (29s) ✅ Passed (40s)
ScopedExtensionPropertiesQualified ✅ Failed as expected (28s) ✅ Passed (41s)
ScopedExtensionPropertiesReadOnlyMember ✅ Failed as expected (29s) ✅ Passed (45s)
Execution log excerpts

Without fix ExtensionPropertyMetadataTests

     at Microsoft.Maui.Controls.SourceGen.UnitTests.ExtensionPropertyMetadataTests.MetadataPropertyIsAvailableToMarkupExtensionWithRoslyn412() in /_/src/Controls/tests/SourceGen.UnitTests/InitializeComponent/ExtensionPropertyMetadataTests.cs:line 42
   at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

With fix ExtensionPropertyMetadataTests

  Determining projects to restore...
  All projects are up-to-date for restore.
Test run for /home/vsts/work/1/s/artifacts/bin/SourceGen.UnitTests/Debug/net11.0/Microsoft.Maui.Controls.SourceGen.UnitTests.dll (.NETCoreApp,Version=v11.0)
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.8.2+699d445a1a (64-bit .NET 11.0.0)
[xUnit.net 00:00:00.26]   Discovering: Microsoft.Maui.Controls.SourceGen.UnitTests
[xUnit.net 00:00:00.60]   Discovered:  Microsoft.Maui.Controls.SourceGen.UnitTests
[xUnit.net 00:00:00.62]   Starting:    Microsoft.Maui.Controls.SourceGen.UnitTests
[xUnit.net 00:00:05.53]   Finished:    Microsoft.Maui.Controls.SourceGen.UnitTests
  Passed Microsoft.Maui.Controls.SourceGen.UnitTests.ExtensionPropertyMetadataTests.MetadataPropertyIsAvailableToMarkupExtensionWithRoslyn412 [4 s]
Test Run Successful.
Total tests: 1
     Passed: 1
 Total time: 6.5463 Seconds

Without fix GlobalScopedExtensionProperties

     at Microsoft.Maui.Controls.Xaml.UnitTests.ExtensionPropertyTestHelper.Emit(Compilation compilation, GeneratorDriverRunResult result, String fullName) in /_/src/Controls/tests/Xaml.UnitTests/ExtensionPropertyTestHelper.cs:line 108
   at Microsoft.Maui.Controls.Xaml.UnitTests.ExtensionPropertyTestHelper.Compile(Type fixture) in /_/src/Controls/tests/Xaml.UnitTests/ExtensionPropertyTestHelper.cs:line 42
   at Microsoft.Maui.Controls.Xaml.UnitTests.GlobalScopedExtensionProperties.Tests.<>c.<.cctor>b__5_0() in /_/src/Controls/tests/Xaml.UnitTests/GlobalScopedExtensionProperties.rt.xaml.cs:line 24
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at Microsoft.Maui.Controls.Xaml.UnitTests.GlobalScopedExtensionProperties.Tests.GlobalScopedExtensionProperties_UnqualifiedExtensionPropertyFromTheGlobalXmlns() in /_/src/Controls/tests/Xaml.UnitTests/GlobalScopedExtensionProperties.rt.xaml.cs:line 41
   at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.Maui.Controls.Xaml.UnitTests.GlobalScopedExtensionProperties.Tests.GlobalScopedExtensionProperties_MappedNamespaceBeginningWithHttpIsInScope() in /_/src/Controls/tests/Xaml.UnitTests/GlobalScopedExtensionProperties.rt.xaml.cs:line 45

With fix GlobalScopedExtensionProperties

  Determining projects to restore...
  All projects are up-to-date for restore.
Test run for /home/vsts/work/1/s/artifacts/bin/Controls.Xaml.UnitTests/Debug/net11.0/Microsoft.Maui.Controls.Xaml.UnitTests.dll (.NETCoreApp,Version=v11.0)
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.8.2+699d445a1a (64-bit .NET 11.0.0)
[xUnit.net 00:00:00.58]   Discovering: Microsoft.Maui.Controls.Xaml.UnitTests
[xUnit.net 00:00:07.96]   Discovered:  Microsoft.Maui.Controls.Xaml.UnitTests
[xUnit.net 00:00:07.97]   Starting:    Microsoft.Maui.Controls.Xaml.UnitTests
  Passed GlobalScopedExtensionProperties_UnqualifiedExtensionPropertyFromTheGlobalXmlns [3 s]
[xUnit.net 00:00:11.27]   Finished:    Microsoft.Maui.Controls.Xaml.UnitTests
  Passed GlobalScopedExtensionProperties_MappedNamespaceBeginningWithHttpIsInScope [< 1 ms]
Test Run Successful.
Total tests: 2
     Passed: 2
 Total time: 12.3697 Seconds

PR head: 368d7276.

Without-fix baseline: 14c3ea20.

@MauiBot MauiBot removed the s/agent-review-in-progress AI review is currently running for this PR label Nov 16, 2026
@kubaflo

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

Tests Failure Analysis

@StephaneDelcroix — test-failure analysis for commit 368d727.

Scope CI failures Commit 368d727


🧪 CI Analysis — click to expand
📊 maui-pr

No failures found.


🧪 maui-pr-devicetests

No failures found.


🧪 maui-pr-uitests

Matching failures predate the XAML changes; handlers/setup are unchanged. All five target histories are partial.


🧭 Follow-up — actions and refresh

Next action: Compare FlexLayout/TitleBar on base/head with identical runtime/OS; inspect screenshots/generated XAML.

Maintainers: comment /review tests to refresh this report.

@kubaflo
kubaflo changed the base branch from main to candidate/11.0.1xx-sr2 November 17, 2026 11:19
Preserve the existing MAUIX2020 namespace conflict warning and assign MAUIX2022 to extension property resolution errors, updating regression assertions to avoid a diagnostic ID collision.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@kubaflo

kubaflo commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Resolved the conflict with candidate/11.0.1xx-sr2 and pushed merge commit 53509beaa1 to the original feature/csharp14-extension-properties-xaml branch.

Preserved the target’s MAUIX2020 namespace-conflict warning and assigned MAUIX2022 to the PR’s extension-property resolution error, avoiding a diagnostic-ID collision. Updated the corresponding assertions and retained both extension-property and namespace-conflict behavior and regression suites.

@kubaflo
kubaflo merged commit b471e93 into candidate/11.0.1xx-sr2 Nov 17, 2026
2 of 12 checks passed
@kubaflo
kubaflo deleted the feature/csharp14-extension-properties-xaml branch November 17, 2026 11:27
@kubaflo kubaflo mentioned this pull request Nov 17, 2026
1 task
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!

### Description of Change

Adds C# 14 extension-property assignment to the XAML source generator.

Extension properties can be used without qualification when their
container is in the element's effective default XAML namespace:

```csharp
[assembly: XmlnsDefinition(
	"http://schemas.microsoft.com/dotnet/2021/maui",
	"MyApp.Extensions")]

namespace MyApp.Extensions;

public static class LabelExtensions
{
	extension(Label label)
	{
		public string MyTag { get; set; }
	}
}
```

```xml
<Label MyTag="hello" />
```

Containers introduced through MAUI's global XML namespace are also
available to XAML documents using that namespace. Explicit qualification
remains available for selection and disambiguation:

```xml
<Label local:LabelExtensions.MyTag="hello" />
```

## Resolution rules

- Ordinary events, BindableProperties, and instance properties retain
precedence over extension properties.
- Unqualified extension properties are discovered only in CLR namespaces
mapped from the element's effective default `xmlns`; no global assembly
scan is performed.
- The container must be a non-generic static class containing a
compiler-generated C# extension declaration.
- Only the compiler-emitted setter of an actual extension property
declaration is called (matching receiver and value type); a hand-written
static `set_Name` method is never treated as an accessor.
- An accessible instance property or field hides extension properties of
the same name even when it cannot be assigned, as in C# (explicitly
implemented interface properties hide nothing).
- An `[XmlnsDefinition]` only brings its namespace in from the assembly
it names.
- All applicable setters of all in-scope containers compete together;
the unique most-specific receiver wins, independent of declaration or
metadata order.
- Equal or unrelated applicable candidates produce `MAUIX2021`,
including when the ambiguity is inside one container.
- An explicitly named extension container that does not define the
requested property produces `MAUIX2020` and cannot fall through to an
unrelated target property.
- Values can come from markup extensions such as `{StaticResource}`, and
the extension property's own `[TypeConverter]` is honoured.

## Support matrix

| Inflator | Support |
|----------|---------|
| SourceGen | Supported: unqualified namespace-scoped and explicitly
qualified assignment |
| XamlC | Not supported |
| Runtime XAML inflation | Not supported |

XamlC and Runtime retain their existing unresolved-member behavior.
Their product code is unchanged by this PR.

Direct binding paths such as `{Binding Person.FullName}` remain out of
scope. Extension properties are static accessors rather than reflected
instance properties and do not define change-notification semantics.

## Tests

SourceGen coverage includes:

- Default-namespace and global-namespace lookup.
- Cross-assembly namespace mappings.
- Instance-property precedence.
- Most-specific receiver selection across two and three containers, in
different declaration orders.
- Ambiguous candidates and out-of-scope containers.
- Explicit qualification and disambiguation.
- Handwritten lookalike accessor rejection.
- Qualified property-element compatibility, including
`<ContentView.Resources>` on a `ContentPage`.
- `{StaticResource}` values, hand-written `set_Name` lookalikes,
ambiguity inside one container, unassignable and explicitly implemented
instance members, and containers from an unmapped assembly sharing a
mapped namespace.

Validation after rebasing on `main` (macOS):

- `dotnet test
src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj
--filter FullyQualifiedName~ExtensionProperties`: 19 passed. The 5 new
regression tests fail on the previous generator.
- `dotnet test
src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj`: 2,198
passed, 8 skipped, 2 failed (`TwoWayDecimalBinding_INPC`/`_VMToUI`,
locale-dependent decimal parsing in `CSharpExpressions`, unrelated to
this PR).
- `dotnet test
src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj`: 628
passed, 40 skipped.

### Issues Fixed

None (new feature).

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
Copilot-Session: c30817d7-694e-4593-8efc-dc56ecfaeba1
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!

### Description of Change

Adds C# 14 extension-property assignment to the XAML source generator.

Extension properties can be used without qualification when their
container is in the element's effective default XAML namespace:

```csharp
[assembly: XmlnsDefinition(
	"http://schemas.microsoft.com/dotnet/2021/maui",
	"MyApp.Extensions")]

namespace MyApp.Extensions;

public static class LabelExtensions
{
	extension(Label label)
	{
		public string MyTag { get; set; }
	}
}
```

```xml
<Label MyTag="hello" />
```

Containers introduced through MAUI's global XML namespace are also
available to XAML documents using that namespace. Explicit qualification
remains available for selection and disambiguation:

```xml
<Label local:LabelExtensions.MyTag="hello" />
```

## Resolution rules

- Ordinary events, BindableProperties, and instance properties retain
precedence over extension properties.
- Unqualified extension properties are discovered only in CLR namespaces
mapped from the element's effective default `xmlns`; no global assembly
scan is performed.
- The container must be a non-generic static class containing a
compiler-generated C# extension declaration.
- Only the compiler-emitted setter of an actual extension property
declaration is called (matching receiver and value type); a hand-written
static `set_Name` method is never treated as an accessor.
- An accessible instance property or field hides extension properties of
the same name even when it cannot be assigned, as in C# (explicitly
implemented interface properties hide nothing).
- An `[XmlnsDefinition]` only brings its namespace in from the assembly
it names.
- All applicable setters of all in-scope containers compete together;
the unique most-specific receiver wins, independent of declaration or
metadata order.
- Equal or unrelated applicable candidates produce `MAUIX2021`,
including when the ambiguity is inside one container.
- An explicitly named extension container that does not define the
requested property produces `MAUIX2020` and cannot fall through to an
unrelated target property.
- Values can come from markup extensions such as `{StaticResource}`, and
the extension property's own `[TypeConverter]` is honoured.

## Support matrix

| Inflator | Support |
|----------|---------|
| SourceGen | Supported: unqualified namespace-scoped and explicitly
qualified assignment |
| XamlC | Not supported |
| Runtime XAML inflation | Not supported |

XamlC and Runtime retain their existing unresolved-member behavior.
Their product code is unchanged by this PR.

Direct binding paths such as `{Binding Person.FullName}` remain out of
scope. Extension properties are static accessors rather than reflected
instance properties and do not define change-notification semantics.

## Tests

SourceGen coverage includes:

- Default-namespace and global-namespace lookup.
- Cross-assembly namespace mappings.
- Instance-property precedence.
- Most-specific receiver selection across two and three containers, in
different declaration orders.
- Ambiguous candidates and out-of-scope containers.
- Explicit qualification and disambiguation.
- Handwritten lookalike accessor rejection.
- Qualified property-element compatibility, including
`<ContentView.Resources>` on a `ContentPage`.
- `{StaticResource}` values, hand-written `set_Name` lookalikes,
ambiguity inside one container, unassignable and explicitly implemented
instance members, and containers from an unmapped assembly sharing a
mapped namespace.

Validation after rebasing on `main` (macOS):

- `dotnet test
src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj
--filter FullyQualifiedName~ExtensionProperties`: 19 passed. The 5 new
regression tests fail on the previous generator.
- `dotnet test
src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj`: 2,198
passed, 8 skipped, 2 failed (`TwoWayDecimalBinding_INPC`/`_VMToUI`,
locale-dependent decimal parsing in `CSharpExpressions`, unrelated to
this PR).
- `dotnet test
src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj`: 628
passed, 40 skipped.

### Issues Fixed

None (new feature).

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
Copilot-Session: c30817d7-694e-4593-8efc-dc56ecfaeba1
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!

### Description of Change

Adds C# 14 extension-property assignment to the XAML source generator.

Extension properties can be used without qualification when their
container is in the element's effective default XAML namespace:

```csharp
[assembly: XmlnsDefinition(
	"http://schemas.microsoft.com/dotnet/2021/maui",
	"MyApp.Extensions")]

namespace MyApp.Extensions;

public static class LabelExtensions
{
	extension(Label label)
	{
		public string MyTag { get; set; }
	}
}
```

```xml
<Label MyTag="hello" />
```

Containers introduced through MAUI's global XML namespace are also
available to XAML documents using that namespace. Explicit qualification
remains available for selection and disambiguation:

```xml
<Label local:LabelExtensions.MyTag="hello" />
```

## Resolution rules

- Ordinary events, BindableProperties, and instance properties retain
precedence over extension properties.
- Unqualified extension properties are discovered only in CLR namespaces
mapped from the element's effective default `xmlns`; no global assembly
scan is performed.
- The container must be a non-generic static class containing a
compiler-generated C# extension declaration.
- Only the compiler-emitted setter of an actual extension property
declaration is called (matching receiver and value type); a hand-written
static `set_Name` method is never treated as an accessor.
- An accessible instance property or field hides extension properties of
the same name even when it cannot be assigned, as in C# (explicitly
implemented interface properties hide nothing).
- An `[XmlnsDefinition]` only brings its namespace in from the assembly
it names.
- All applicable setters of all in-scope containers compete together;
the unique most-specific receiver wins, independent of declaration or
metadata order.
- Equal or unrelated applicable candidates produce `MAUIX2021`,
including when the ambiguity is inside one container.
- An explicitly named extension container that does not define the
requested property produces `MAUIX2020` and cannot fall through to an
unrelated target property.
- Values can come from markup extensions such as `{StaticResource}`, and
the extension property's own `[TypeConverter]` is honoured.

## Support matrix

| Inflator | Support |
|----------|---------|
| SourceGen | Supported: unqualified namespace-scoped and explicitly
qualified assignment |
| XamlC | Not supported |
| Runtime XAML inflation | Not supported |

XamlC and Runtime retain their existing unresolved-member behavior.
Their product code is unchanged by this PR.

Direct binding paths such as `{Binding Person.FullName}` remain out of
scope. Extension properties are static accessors rather than reflected
instance properties and do not define change-notification semantics.

## Tests

SourceGen coverage includes:

- Default-namespace and global-namespace lookup.
- Cross-assembly namespace mappings.
- Instance-property precedence.
- Most-specific receiver selection across two and three containers, in
different declaration orders.
- Ambiguous candidates and out-of-scope containers.
- Explicit qualification and disambiguation.
- Handwritten lookalike accessor rejection.
- Qualified property-element compatibility, including
`<ContentView.Resources>` on a `ContentPage`.
- `{StaticResource}` values, hand-written `set_Name` lookalikes,
ambiguity inside one container, unassignable and explicitly implemented
instance members, and containers from an unmapped assembly sharing a
mapped namespace.

Validation after rebasing on `main` (macOS):

- `dotnet test
src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj
--filter FullyQualifiedName~ExtensionProperties`: 19 passed. The 5 new
regression tests fail on the previous generator.
- `dotnet test
src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj`: 2,198
passed, 8 skipped, 2 failed (`TwoWayDecimalBinding_INPC`/`_VMToUI`,
locale-dependent decimal parsing in `CSharpExpressions`, unrelated to
this PR).
- `dotnet test
src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj`: 628
passed, 40 skipped.

### Issues Fixed

None (new feature).

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
Copilot-Session: c30817d7-694e-4593-8efc-dc56ecfaeba1
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!

### Description of Change

Adds C# 14 extension-property assignment to the XAML source generator.

Extension properties can be used without qualification when their
container is in the element's effective default XAML namespace:

```csharp
[assembly: XmlnsDefinition(
	"http://schemas.microsoft.com/dotnet/2021/maui",
	"MyApp.Extensions")]

namespace MyApp.Extensions;

public static class LabelExtensions
{
	extension(Label label)
	{
		public string MyTag { get; set; }
	}
}
```

```xml
<Label MyTag="hello" />
```

Containers introduced through MAUI's global XML namespace are also
available to XAML documents using that namespace. Explicit qualification
remains available for selection and disambiguation:

```xml
<Label local:LabelExtensions.MyTag="hello" />
```

## Resolution rules

- Ordinary events, BindableProperties, and instance properties retain
precedence over extension properties.
- Unqualified extension properties are discovered only in CLR namespaces
mapped from the element's effective default `xmlns`; no global assembly
scan is performed.
- The container must be a non-generic static class containing a
compiler-generated C# extension declaration.
- Only the compiler-emitted setter of an actual extension property
declaration is called (matching receiver and value type); a hand-written
static `set_Name` method is never treated as an accessor.
- An accessible instance property or field hides extension properties of
the same name even when it cannot be assigned, as in C# (explicitly
implemented interface properties hide nothing).
- An `[XmlnsDefinition]` only brings its namespace in from the assembly
it names.
- All applicable setters of all in-scope containers compete together;
the unique most-specific receiver wins, independent of declaration or
metadata order.
- Equal or unrelated applicable candidates produce `MAUIX2021`,
including when the ambiguity is inside one container.
- An explicitly named extension container that does not define the
requested property produces `MAUIX2020` and cannot fall through to an
unrelated target property.
- Values can come from markup extensions such as `{StaticResource}`, and
the extension property's own `[TypeConverter]` is honoured.

## Support matrix

| Inflator | Support |
|----------|---------|
| SourceGen | Supported: unqualified namespace-scoped and explicitly
qualified assignment |
| XamlC | Not supported |
| Runtime XAML inflation | Not supported |

XamlC and Runtime retain their existing unresolved-member behavior.
Their product code is unchanged by this PR.

Direct binding paths such as `{Binding Person.FullName}` remain out of
scope. Extension properties are static accessors rather than reflected
instance properties and do not define change-notification semantics.

## Tests

SourceGen coverage includes:

- Default-namespace and global-namespace lookup.
- Cross-assembly namespace mappings.
- Instance-property precedence.
- Most-specific receiver selection across two and three containers, in
different declaration orders.
- Ambiguous candidates and out-of-scope containers.
- Explicit qualification and disambiguation.
- Handwritten lookalike accessor rejection.
- Qualified property-element compatibility, including
`<ContentView.Resources>` on a `ContentPage`.
- `{StaticResource}` values, hand-written `set_Name` lookalikes,
ambiguity inside one container, unassignable and explicitly implemented
instance members, and containers from an unmapped assembly sharing a
mapped namespace.

Validation after rebasing on `main` (macOS):

- `dotnet test
src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj
--filter FullyQualifiedName~ExtensionProperties`: 19 passed. The 5 new
regression tests fail on the previous generator.
- `dotnet test
src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj`: 2,198
passed, 8 skipped, 2 failed (`TwoWayDecimalBinding_INPC`/`_VMToUI`,
locale-dependent decimal parsing in `CSharpExpressions`, unrelated to
this PR).
- `dotnet test
src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj`: 628
passed, 40 skipped.

### Issues Fixed

None (new feature).

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
Copilot-Session: c30817d7-694e-4593-8efc-dc56ecfaeba1
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!

### Description of Change

Adds C# 14 extension-property assignment to the XAML source generator.

Extension properties can be used without qualification when their
container is in the element's effective default XAML namespace:

```csharp
[assembly: XmlnsDefinition(
	"http://schemas.microsoft.com/dotnet/2021/maui",
	"MyApp.Extensions")]

namespace MyApp.Extensions;

public static class LabelExtensions
{
	extension(Label label)
	{
		public string MyTag { get; set; }
	}
}
```

```xml
<Label MyTag="hello" />
```

Containers introduced through MAUI's global XML namespace are also
available to XAML documents using that namespace. Explicit qualification
remains available for selection and disambiguation:

```xml
<Label local:LabelExtensions.MyTag="hello" />
```

## Resolution rules

- Ordinary events, BindableProperties, and instance properties retain
precedence over extension properties.
- Unqualified extension properties are discovered only in CLR namespaces
mapped from the element's effective default `xmlns`; no global assembly
scan is performed.
- The container must be a non-generic static class containing a
compiler-generated C# extension declaration.
- Only the compiler-emitted setter of an actual extension property
declaration is called (matching receiver and value type); a hand-written
static `set_Name` method is never treated as an accessor.
- An accessible instance property or field hides extension properties of
the same name even when it cannot be assigned, as in C# (explicitly
implemented interface properties hide nothing).
- An `[XmlnsDefinition]` only brings its namespace in from the assembly
it names.
- All applicable setters of all in-scope containers compete together;
the unique most-specific receiver wins, independent of declaration or
metadata order.
- Equal or unrelated applicable candidates produce `MAUIX2021`,
including when the ambiguity is inside one container.
- An explicitly named extension container that does not define the
requested property produces `MAUIX2020` and cannot fall through to an
unrelated target property.
- Values can come from markup extensions such as `{StaticResource}`, and
the extension property's own `[TypeConverter]` is honoured.

## Support matrix

| Inflator | Support |
|----------|---------|
| SourceGen | Supported: unqualified namespace-scoped and explicitly
qualified assignment |
| XamlC | Not supported |
| Runtime XAML inflation | Not supported |

XamlC and Runtime retain their existing unresolved-member behavior.
Their product code is unchanged by this PR.

Direct binding paths such as `{Binding Person.FullName}` remain out of
scope. Extension properties are static accessors rather than reflected
instance properties and do not define change-notification semantics.

## Tests

SourceGen coverage includes:

- Default-namespace and global-namespace lookup.
- Cross-assembly namespace mappings.
- Instance-property precedence.
- Most-specific receiver selection across two and three containers, in
different declaration orders.
- Ambiguous candidates and out-of-scope containers.
- Explicit qualification and disambiguation.
- Handwritten lookalike accessor rejection.
- Qualified property-element compatibility, including
`<ContentView.Resources>` on a `ContentPage`.
- `{StaticResource}` values, hand-written `set_Name` lookalikes,
ambiguity inside one container, unassignable and explicitly implemented
instance members, and containers from an unmapped assembly sharing a
mapped namespace.

Validation after rebasing on `main` (macOS):

- `dotnet test
src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj
--filter FullyQualifiedName~ExtensionProperties`: 19 passed. The 5 new
regression tests fail on the previous generator.
- `dotnet test
src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj`: 2,198
passed, 8 skipped, 2 failed (`TwoWayDecimalBinding_INPC`/`_VMToUI`,
locale-dependent decimal parsing in `CSharpExpressions`, unrelated to
this PR).
- `dotnet test
src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj`: 628
passed, 40 skipped.

### Issues Fixed

None (new feature).

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
Copilot-Session: c30817d7-694e-4593-8efc-dc56ecfaeba1
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!

### Description of Change

Adds C# 14 extension-property assignment to the XAML source generator.

Extension properties can be used without qualification when their
container is in the element's effective default XAML namespace:

```csharp
[assembly: XmlnsDefinition(
	"http://schemas.microsoft.com/dotnet/2021/maui",
	"MyApp.Extensions")]

namespace MyApp.Extensions;

public static class LabelExtensions
{
	extension(Label label)
	{
		public string MyTag { get; set; }
	}
}
```

```xml
<Label MyTag="hello" />
```

Containers introduced through MAUI's global XML namespace are also
available to XAML documents using that namespace. Explicit qualification
remains available for selection and disambiguation:

```xml
<Label local:LabelExtensions.MyTag="hello" />
```

## Resolution rules

- Ordinary events, BindableProperties, and instance properties retain
precedence over extension properties.
- Unqualified extension properties are discovered only in CLR namespaces
mapped from the element's effective default `xmlns`; no global assembly
scan is performed.
- The container must be a non-generic static class containing a
compiler-generated C# extension declaration.
- Only the compiler-emitted setter of an actual extension property
declaration is called (matching receiver and value type); a hand-written
static `set_Name` method is never treated as an accessor.
- An accessible instance property or field hides extension properties of
the same name even when it cannot be assigned, as in C# (explicitly
implemented interface properties hide nothing).
- An `[XmlnsDefinition]` only brings its namespace in from the assembly
it names.
- All applicable setters of all in-scope containers compete together;
the unique most-specific receiver wins, independent of declaration or
metadata order.
- Equal or unrelated applicable candidates produce `MAUIX2021`,
including when the ambiguity is inside one container.
- An explicitly named extension container that does not define the
requested property produces `MAUIX2020` and cannot fall through to an
unrelated target property.
- Values can come from markup extensions such as `{StaticResource}`, and
the extension property's own `[TypeConverter]` is honoured.

## Support matrix

| Inflator | Support |
|----------|---------|
| SourceGen | Supported: unqualified namespace-scoped and explicitly
qualified assignment |
| XamlC | Not supported |
| Runtime XAML inflation | Not supported |

XamlC and Runtime retain their existing unresolved-member behavior.
Their product code is unchanged by this PR.

Direct binding paths such as `{Binding Person.FullName}` remain out of
scope. Extension properties are static accessors rather than reflected
instance properties and do not define change-notification semantics.

## Tests

SourceGen coverage includes:

- Default-namespace and global-namespace lookup.
- Cross-assembly namespace mappings.
- Instance-property precedence.
- Most-specific receiver selection across two and three containers, in
different declaration orders.
- Ambiguous candidates and out-of-scope containers.
- Explicit qualification and disambiguation.
- Handwritten lookalike accessor rejection.
- Qualified property-element compatibility, including
`<ContentView.Resources>` on a `ContentPage`.
- `{StaticResource}` values, hand-written `set_Name` lookalikes,
ambiguity inside one container, unassignable and explicitly implemented
instance members, and containers from an unmapped assembly sharing a
mapped namespace.

Validation after rebasing on `main` (macOS):

- `dotnet test
src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj
--filter FullyQualifiedName~ExtensionProperties`: 19 passed. The 5 new
regression tests fail on the previous generator.
- `dotnet test
src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj`: 2,198
passed, 8 skipped, 2 failed (`TwoWayDecimalBinding_INPC`/`_VMToUI`,
locale-dependent decimal parsing in `CSharpExpressions`, unrelated to
this PR).
- `dotnet test
src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj`: 628
passed, 40 skipped.

### Issues Fixed

None (new feature).

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
Copilot-Session: c30817d7-694e-4593-8efc-dc56ecfaeba1
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!

### Description of Change

Adds C# 14 extension-property assignment to the XAML source generator.

Extension properties can be used without qualification when their
container is in the element's effective default XAML namespace:

```csharp
[assembly: XmlnsDefinition(
	"http://schemas.microsoft.com/dotnet/2021/maui",
	"MyApp.Extensions")]

namespace MyApp.Extensions;

public static class LabelExtensions
{
	extension(Label label)
	{
		public string MyTag { get; set; }
	}
}
```

```xml
<Label MyTag="hello" />
```

Containers introduced through MAUI's global XML namespace are also
available to XAML documents using that namespace. Explicit qualification
remains available for selection and disambiguation:

```xml
<Label local:LabelExtensions.MyTag="hello" />
```

## Resolution rules

- Ordinary events, BindableProperties, and instance properties retain
precedence over extension properties.
- Unqualified extension properties are discovered only in CLR namespaces
mapped from the element's effective default `xmlns`; no global assembly
scan is performed.
- The container must be a non-generic static class containing a
compiler-generated C# extension declaration.
- Only the compiler-emitted setter of an actual extension property
declaration is called (matching receiver and value type); a hand-written
static `set_Name` method is never treated as an accessor.
- An accessible instance property or field hides extension properties of
the same name even when it cannot be assigned, as in C# (explicitly
implemented interface properties hide nothing).
- An `[XmlnsDefinition]` only brings its namespace in from the assembly
it names.
- All applicable setters of all in-scope containers compete together;
the unique most-specific receiver wins, independent of declaration or
metadata order.
- Equal or unrelated applicable candidates produce `MAUIX2021`,
including when the ambiguity is inside one container.
- An explicitly named extension container that does not define the
requested property produces `MAUIX2020` and cannot fall through to an
unrelated target property.
- Values can come from markup extensions such as `{StaticResource}`, and
the extension property's own `[TypeConverter]` is honoured.

## Support matrix

| Inflator | Support |
|----------|---------|
| SourceGen | Supported: unqualified namespace-scoped and explicitly
qualified assignment |
| XamlC | Not supported |
| Runtime XAML inflation | Not supported |

XamlC and Runtime retain their existing unresolved-member behavior.
Their product code is unchanged by this PR.

Direct binding paths such as `{Binding Person.FullName}` remain out of
scope. Extension properties are static accessors rather than reflected
instance properties and do not define change-notification semantics.

## Tests

SourceGen coverage includes:

- Default-namespace and global-namespace lookup.
- Cross-assembly namespace mappings.
- Instance-property precedence.
- Most-specific receiver selection across two and three containers, in
different declaration orders.
- Ambiguous candidates and out-of-scope containers.
- Explicit qualification and disambiguation.
- Handwritten lookalike accessor rejection.
- Qualified property-element compatibility, including
`<ContentView.Resources>` on a `ContentPage`.
- `{StaticResource}` values, hand-written `set_Name` lookalikes,
ambiguity inside one container, unassignable and explicitly implemented
instance members, and containers from an unmapped assembly sharing a
mapped namespace.

Validation after rebasing on `main` (macOS):

- `dotnet test
src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj
--filter FullyQualifiedName~ExtensionProperties`: 19 passed. The 5 new
regression tests fail on the previous generator.
- `dotnet test
src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj`: 2,198
passed, 8 skipped, 2 failed (`TwoWayDecimalBinding_INPC`/`_VMToUI`,
locale-dependent decimal parsing in `CSharpExpressions`, unrelated to
this PR).
- `dotnet test
src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj`: 628
passed, 40 skipped.

### Issues Fixed

None (new feature).

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
Copilot-Session: c30817d7-694e-4593-8efc-dc56ecfaeba1
@kubaflo kubaflo added this to the .NET 11 SR2 milestone Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge Don't merge this PR s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-fix-win AI found a better alternative fix than the PR s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix) s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants