Skip to content

Conversation

@StephaneDelcroix
Copy link
Contributor

@StephaneDelcroix StephaneDelcroix commented Nov 24, 2025

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

The XAML Source Generator was failing with MAUIX2003: "No method found for..." when third-party controls used <x:Arguments> with interface-typed constructor parameters.

Root Cause

In IMethodSymbolExtensions.cs, the MatchXArguments method checked class inheritance before interface implementation. For interface parameters, the inheritance check would fail and return false immediately, never reaching the interface implementation check.

The Fix

Reordered the type-checking logic to:

  1. Check interface implementation first for interface parameters
  2. Check class inheritance for class parameters

This enables third-party libraries like CardView.MAUI and MauiIcons that use dependency injection patterns with interface-typed constructor parameters to work correctly with XAML Source Generation.

Issues Fixed

Fixes #32764

API Changes

None

Platforms Affected

  • All (the fix is in the XAML Source Generator)

Behavioral Changes

Controls using <x:Arguments> with interface parameters now work correctly with XAML Source Generation. Previously, these would fail to compile with MAUIX2003 errors.

Testing

  • ✅ Added unit test Maui32764 that validates x:Arguments with interface parameters for all XAML inflator modes (Runtime, XamlC, SourceGen)
  • ✅ Test passes for all 3 inflator modes
  • ✅ Validated fix with CardView.MAUI sample project - build succeeded with 0 MAUIX2003 errors (previously 4 errors)

PR Checklist

  • Has tests (added unit test)
  • Rebased on top of the target branch at time of PR
  • Changes adhere to coding standard
  • Consolidated commits where it makes sense (single commit)

Fixes #32764

The XAML Source Generator was incorrectly checking class inheritance
before interface implementation when matching constructor parameters
in x:Arguments. This caused third-party controls using dependency
injection patterns with interface-typed constructor parameters to
fail with MAUIX2003 errors.

The fix reorders the type-checking logic in MatchXArguments to:
1. Check interface implementation first for interface parameters
2. Check class inheritance for class parameters

This enables third-party libraries like CardView.MAUI and MauiIcons
to work correctly with XAML Source Generation.

Changes:
- Fixed parameter type matching in IMethodSymbolExtensions.cs
- Added unit test validating x:Arguments with interface parameters
  for all XAML inflator modes (Runtime, XamlC, SourceGen)
Copilot AI review requested due to automatic review settings November 24, 2025 08:49
@StephaneDelcroix StephaneDelcroix changed the title Fix MAUIX2003 error for x:Arguments with interface parameters [XSG] Fix MAUIX2003 error for x:Arguments with interface parameters Nov 24, 2025
@StephaneDelcroix StephaneDelcroix added area-xaml XAML, CSS, Triggers, Behaviors xsg Xaml sourceGen labels Nov 24, 2025
@StephaneDelcroix StephaneDelcroix added this to the .NET 10.0 SR2 milestone Nov 24, 2025
Copilot finished reviewing on behalf of StephaneDelcroix November 24, 2025 08:52
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes issue #32764 where the XAML Source Generator incorrectly threw MAUIX2003 errors when processing <x:Arguments> with interface-typed constructor parameters in third-party controls.

Key Changes

  • Reordered type-checking logic in MatchXArguments to check interface implementation before class inheritance
  • Added comprehensive unit test validating the fix across all XAML inflator modes (Runtime, XamlC, SourceGen)

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/Controls/src/SourceGen/IMethodSymbolExtensions.cs Fixed the MatchXArguments method to check if parameter type is an interface first, then use Implements() for interface parameters and InheritsFrom() for class parameters. This prevents the method from incorrectly rejecting constructors with interface parameters.
src/Controls/tests/Xaml.UnitTests/Issues/Maui32764.xaml Added XAML test case that instantiates a control (TestCarouselView) using <x:Arguments> with a concrete class (TestProcessor) passed to a constructor expecting an interface parameter (ITestProcessor).
src/Controls/tests/Xaml.UnitTests/Issues/Maui32764.xaml.cs Added test infrastructure including interface/class definitions simulating third-party control patterns and a unit test validating all XAML inflator modes. Note: Missing required constructor overload.


public partial class Maui32764 : ContentPage
{
public Maui32764() => InitializeComponent();
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing constructor overload that accepts XamlInflator parameter. The test at line 53 calls new Maui32764(inflator), but the class only has a parameterless constructor.

Add the following constructor:

public Maui32764(XamlInflator inflator) => InitializeComponent(inflator);

This constructor is required for the test framework to instantiate the page with different XAML inflation modes (Runtime, XamlC, SourceGen).

Suggested change
public Maui32764() => InitializeComponent();
public Maui32764() => InitializeComponent();
public Maui32764(XamlInflator inflator) => InitializeComponent(inflator);

Copilot uses AI. Check for mistakes.
@jfversluis jfversluis merged commit f915bb9 into main Nov 24, 2025
67 of 68 checks passed
@jfversluis jfversluis deleted the fix/32764-xarguments-interface-parameters branch November 24, 2025 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-xaml XAML, CSS, Triggers, Behaviors xsg Xaml sourceGen

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[.NET 10] Xaml Source Gen - MAUIX2003 error using CardView.MAUI

3 participants