Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Source generator error - The call is ambiguous between the following methods or properties - CommunityToolkit.Maui.Markup.TextAlignmentExtensions #158

Closed
1 task done
egvijayanand opened this issue Nov 28, 2022 · 3 comments · Fixed by #159 or #161
Labels
bug Something isn't working

Comments

@egvijayanand
Copy link

egvijayanand commented Nov 28, 2022

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

  1. Clone the project in the repository mentioned
  2. Try to build the project
  3. 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.

@egvijayanand egvijayanand added bug Something isn't working unverified Bug has not been verified by maintainers labels Nov 28, 2022
egvijayanand added a commit to egvijayanand/markup-issue-158 that referenced this issue Nov 28, 2022
@brminnick brminnick added the needs reproduction This Issue requires a small reproduction sample in order to reproduce the error label Nov 28, 2022
egvijayanand added a commit to egvijayanand/markup-issue-158 that referenced this issue Nov 28, 2022
@egvijayanand
Copy link
Author

egvijayanand commented Nov 28, 2022

Sample project has been pushed into this repo for simulation.

https://github.com/egvijayanand/markup-issue-158

@brminnick brminnick removed unverified Bug has not been verified by maintainers needs reproduction This Issue requires a small reproduction sample in order to reproduce the error labels Nov 28, 2022
@brminnick
Copy link
Collaborator

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

@egvijayanand
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants