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] Ambiguous reference error occurs when other package is included that provides its own Color object #1331

Closed
2 tasks done
wolfgang-ironsoftware opened this issue Aug 10, 2023 · 6 comments · Fixed by #1332
Labels
bug Something isn't working

Comments

@wolfgang-ironsoftware
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Did you read the "Reporting a bug" section on Contributing file?

Current Behavior

When creating a new MAUI project and adding MAUI Community Tookit and another project that includes its own Color object (e.g. SixLabors.ImageSharp, the following error occurs:

Error CS0104 'Color' is an ambiguous reference between 'Microsoft.Maui.Graphics.Color' and 'SixLabors.ImageSharp.Color' MauiCommunityToolkitColorIssue (net7.0-android)
C:...\MauiCommunityToolkitColorIssue\MauiCommunityToolkitColorIssue\CommunityToolkit.Maui.SourceGenerators\CommunityToolkit.Maui.SourceGenerators.Generators.TextColorToGenerator\EditorTextColorTo.g.shared.cs 23

Expected Behavior

No error should occur.

Steps To Reproduce

  1. Create a new MAUI project
  2. Add CommunityToolkit.Maui nuget
  3. Add SixLabors.ImageSharp nuget
  4. Compile the project

Link to public reproduction project repository

https://github.com/wolfgang-ironsoftware/MauiCommunityToolkitColorIssue

Environment

- .NET MAUI CommunityToolkit: 5.3.0
- OS: Windows 11
- .NET MAUI: 7.0.92

Anything else?

No response

@brminnick
Copy link
Collaborator

There's nothing we can do in the .NET MAUI Community Toolkit to resolve the fact that ImageSharp and .NET MAUI both have a class named Color.

We don't control either of those repositories.

@brminnick brminnick closed this as not planned Won't fix, can't repro, duplicate, stale Aug 10, 2023
@brminnick
Copy link
Collaborator

Apologies. I understand now that it is our Source Generator generating code causing the naming conflict. Thanks for the PR!

@brminnick brminnick reopened this Aug 10, 2023
@pictos
Copy link
Member

pictos commented Aug 10, 2023

The workaround is to create a GlobalUsing file and this line there

global using Color = Microsoft.Maui.Graphics.Color;

@IIARROWS
Copy link
Contributor

The workaround is to create a GlobalUsing file and this line there

global using Color = Microsoft.Maui.Graphics.Color;

The workaround doesn't work. I need the exact opposite.
Why is CommunityToolkit generating code in the first place place? I only installed for the save dialog, but it's trying to generate classes like "ColorAnimationExtensions_Picker".

Is this still present in the latest 7.0.0 package?

@IIARROWS
Copy link
Contributor

IIARROWS commented Nov 18, 2023

There is a new assignment of a transparent color to "element.Color", do you prefer if I create new issue for the new PR?

line 36 of the generate file: element.TextColor ??= Colors.Transparent;

EDIT; it is referring to a class Colors and not the enumerator Color. I'll create a new issue.

@brminnick
Copy link
Collaborator

brminnick commented Nov 18, 2023

Is this still present in the latest 7.0.0 package?

@IIARROWS Here's a couple GitHub pro-tips to help you know what has been merged and what hasn't:

  1. This Issue has a linked Pull Request that includes this Issue's bug fix. The linked Pull Request automatically closed this issue when it was merged.
Linked Pull Request Notification of Issue Closed
  1. Clicking into the linked Pull Request, we can find its Commit ID (also known as its SHA or Hash) where it was merged into the main branch
Pull Request Commit ID
  1. Clicking in to the linked Commit ID, we can see all of the Release Tags where this linked Pull Request, we can find its Commit ID has been included:
Commit ID Releases

To answer you question, this bug fix has been included in CommunityToolkit.Maui since v6.0.0

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
Development

Successfully merging a pull request may close this issue.

4 participants