Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/Controls/src/SourceGen/IMethodSymbolExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,23 @@ public static bool MatchXArguments(this IMethodSymbol method, ElementNode enode,
// }

var argType = getNodeValue?.Invoke(nodeparameters[i], paramType)?.Type ?? context.Variables[nodeparameters[i]].Type;
if (!argType.InheritsFrom(paramType, context))

// Check interface implementation first (interfaces don't use inheritance)
if (paramType.IsInterface())
{
parameters = null;
return false;
if (!argType.Implements(paramType))
{
parameters = null;
return false;
}
}
if (paramType.IsInterface() && !argType.Implements(paramType))
// Then check class inheritance
else if (!argType.InheritsFrom(paramType, context))
{
parameters = null;
return false;
}

parameters.Add((nodeparameters[i], paramType, null));
}
return true;
Expand Down
11 changes: 11 additions & 0 deletions src/Controls/tests/Xaml.UnitTests/Issues/Maui32764.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Microsoft.Maui.Controls.Xaml.UnitTests"
x:Class="Microsoft.Maui.Controls.Xaml.UnitTests.Maui32764">
<local:TestCarouselView x:Name="carouselView">
<x:Arguments>
<local:TestProcessor ScaleFactor="0.5" />
</x:Arguments>
</local:TestCarouselView>
</ContentPage>
62 changes: 62 additions & 0 deletions src/Controls/tests/Xaml.UnitTests/Issues/Maui32764.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
using NUnit.Framework;

namespace Microsoft.Maui.Controls.Xaml.UnitTests;

// Simulate third-party control pattern (like CardView.MAUI) where constructors use interface parameters
public interface ITestProcessor
{
}

public class TestProcessor : ITestProcessor
{
public double ScaleFactor { get; set; }
}

public class TestCardsView : ContentView
{
public TestCardsView(ITestProcessor processor)
{
// Constructor that takes interface parameter
}
}

public class TestCarouselView : TestCardsView
{
// Parameterless constructor chains to constructor with interface parameter
public TestCarouselView() : this(new TestProcessor())
{
}

// Constructor with interface parameter that chains to base
public TestCarouselView(ITestProcessor processor) : base(processor)
{
}
}

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.

[TestFixture]
class Tests
{
[Test]
public void XArgumentsWithInterfaceParameterShouldWork([Values] XamlInflator inflator)
{
// This test reproduces issue #32764
// The bug was that MatchXArguments incorrectly checked class inheritance
// before interface implementation, causing it to fail to match constructors
// with interface parameters when using x:Arguments in XAML
var page = new Maui32764(inflator);

// Just verifying the page loads without throwing is sufficient
// The original bug would throw MAUIX2003: "No method found for 'TestCarouselView'"
// because the source generator couldn't match the constructor taking ITestProcessor
Assert.That(page, Is.Not.Null);
Assert.That(page.carouselView, Is.Not.Null);
}
}
}
Loading