[BUG] Source generator error - The call is ambiguous between the following methods or properties - CommunityToolkit.Maui.Markup.TextAlignmentExtensions
egvijayanand opened this issue · 3 comments
Is there an existing issue for this?
- I have searched the existing issues
Current Behavior
This is a peculiar issue as it is getting simulated only when CommunityToolkit.Maui.Markup
is referenced in a class library or dependency for a NuGet package and that is in turn gets referenced in a .NET MAUI App.
Such a scenario results in the below error:
The call is ambiguous between the following methods or properties: 'CommunityToolkit.Maui.Markup.TextAlignmentExtensions_XYZ.TextCenterHorizontal(Microsoft.Maui.Controls.XYZ)' and 'CommunityToolkit.Maui.Markup.TextAlignmentExtensions_XYZ.TextCenterHorizontal(Microsoft.Maui.Controls.XYZ)'
Where XYZ is the type for which the TextCenterHorizontal() extension method is defined.
Detailed error:
Build started...
1>------ Build started: Project: MauiApp6, Configuration: Debug Any CPU ------
1>E:\MauiApp6\MauiApp6\CommunityToolkit.Maui.Markup.SourceGenerators\CommunityToolkit.Maui.Markup.SourceGenerators.TextAlignmentExtensionsGenerator\SearchBarTextAlignmentExtensions.g.cs(122,153,122,173): error CS0121: The call is ambiguous between the following methods or properties: 'CommunityToolkit.Maui.Markup.TextAlignmentExtensions_SearchBar.TextCenterHorizontal(Microsoft.Maui.Controls.SearchBar)' and 'CommunityToolkit.Maui.Markup.TextAlignmentExtensions_SearchBar.TextCenterHorizontal(Microsoft.Maui.Controls.SearchBar)'
1>E:\MauiApp6\MauiApp6\CommunityToolkit.Maui.Markup.SourceGenerators\CommunityToolkit.Maui.Markup.SourceGenerators.TextAlignmentExtensionsGenerator\EntryCellTextAlignmentExtensions.g.cs(122,153,122,173): error CS0121: The call is ambiguous between the following methods or properties: 'CommunityToolkit.Maui.Markup.TextAlignmentExtensions_EntryCell.TextCenterHorizontal(Microsoft.Maui.Controls.EntryCell)' and 'CommunityToolkit.Maui.Markup.TextAlignmentExtensions_EntryCell.TextCenterHorizontal(Microsoft.Maui.Controls.EntryCell)'
1>E:\MauiApp6\MauiApp6\CommunityToolkit.Maui.Markup.SourceGenerators\CommunityToolkit.Maui.Markup.SourceGenerators.TextAlignmentExtensionsGenerator\EditorTextAlignmentExtensions.g.cs(122,147,122,167): error CS0121: The call is ambiguous between the following methods or properties: 'CommunityToolkit.Maui.Markup.TextAlignmentExtensions_Editor.TextCenterHorizontal(Microsoft.Maui.Controls.Editor)' and 'CommunityToolkit.Maui.Markup.TextAlignmentExtensions_Editor.TextCenterHorizontal(Microsoft.Maui.Controls.Editor)'
1>E:\MauiApp6\MauiApp6\CommunityToolkit.Maui.Markup.SourceGenerators\CommunityToolkit.Maui.Markup.SourceGenerators.TextAlignmentExtensionsGenerator\PickerTextAlignmentExtensions.g.cs(122,147,122,167): error CS0121: The call is ambiguous between the following methods or properties: 'CommunityToolkit.Maui.Markup.TextAlignmentExtensions_Picker.TextCenterHorizontal(Microsoft.Maui.Controls.Picker)' and 'CommunityToolkit.Maui.Markup.TextAlignmentExtensions_Picker.TextCenterHorizontal(Microsoft.Maui.Controls.Picker)'
1>E:\MauiApp6\MauiApp6\CommunityToolkit.Maui.Markup.SourceGenerators\CommunityToolkit.Maui.Markup.SourceGenerators.TextAlignmentExtensionsGenerator\EntryTextAlignmentExtensions.g.cs(122,145,122,165): error CS0121: The call is ambiguous between the following methods or properties: 'CommunityToolkit.Maui.Markup.TextAlignmentExtensions_Entry.TextCenterHorizontal(Microsoft.Maui.Controls.Entry)' and 'CommunityToolkit.Maui.Markup.TextAlignmentExtensions_Entry.TextCenterHorizontal(Microsoft.Maui.Controls.Entry)'
1>E:\MauiApp6\MauiApp6\CommunityToolkit.Maui.Markup.SourceGenerators\CommunityToolkit.Maui.Markup.SourceGenerators.TextAlignmentExtensionsGenerator\LabelTextAlignmentExtensions.g.cs(122,145,122,165): error CS0121: The call is ambiguous between the following methods or properties: 'CommunityToolkit.Maui.Markup.TextAlignmentExtensions_Label.TextCenterHorizontal(Microsoft.Maui.Controls.Label)' and 'CommunityToolkit.Maui.Markup.TextAlignmentExtensions_Label.TextCenterHorizontal(Microsoft.Maui.Controls.Label)'
1>Done building project "MauiApp6.csproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========
========== Elapsed 00:00.874 ==========
Expected Behavior
Should compile without any errors.
Steps To Reproduce
- Clone the project in the repository mentioned
- Try to build the project
- Will end up in the source generator error as detailed in the current behavior
In simple terms, whenever this Markup library is an external dependency, it results in this source generator error.
Link to public reproduction project repository
https://github.com/egvijayanand/markup-issue-158
Environment
- .NET MAUI C# Markup CommunityToolkit:2.0.0
- OS: Windows 11 (10.0.22621.819)
- .NET MAUI: .NET 7 (7.0.49)
Anything else?
This issue is encountered only when CommunityToolkit.Maui.Markup
is an external dependency and not getting simulated when directly referenced in the App project.
Sample project has been pushed into this repo for simulation.
Thanks @egvijayanand! We had just been discussing making the class generated by Source Generators internal
instead of public
, which fixes the bug you're experiencing: CommunityToolkit/Maui#756 (comment)
Here's the link to the NuGet Package generated by the PR if you'd like to use it until we get the PR merged + released:
https://dev.azure.com/dotnet/696bc9fd-f160-4e97-a1bd-7cbbb3b58f66/_apis/build/builds/83337/artifacts?artifactName=nuget&api-version=7.0&%24format=zip
Glad to hear that it's getting fixed at the earliest.
Not required immediately. Today, upgraded one of my packages, and while testing got this issue, as it's specific to one method and simulated for all platforms when debugged further. Hence wanted to report and get it fixed.
Will make note of it and test it when released officially.