Skip to content

Ambiguous reference between 'Microsoft.Maui.Graphics.Color' and 'SixLabors.ImageSharp.Color' #2466

Description

@mike-rowley

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of ImageSharp
  • I have verified if the problem exist in both DEBUG and RELEASE mode
  • I have searched open and closed issues to ensure it has not already been reported

ImageSharp version

3.0.1

Other ImageSharp packages and versions

None

Environment (Operating system, version and so on)

Windows 10.0.19045 Build 19045, VS 17.6.1

.NET Framework version

7

Description

Adding SixLabors.ImageSharp to a brand new Maui Project with CommunityToolkit.Maui causes multiple ambiguous reference between 'Microsoft.Maui.Graphics.Color' and 'SixLabors.ImageSharp.Color' errors

Steps to Reproduce

Create a new Maui Project
Add CommunityToolkit.Maui from nuget
Compile the project successfully
Add SixLabors.ImageSharp
Compile the project fails

Images

Not Applicable

Activity

  1. JimBobSquarePants commented on May 26, 2023

    @JimBobSquarePants
    Member

    See #2381

  2. JimBobSquarePants commented on May 26, 2023

    @JimBobSquarePants
    Member

    I'll keep this open as I want to track adding a single key to remove usings and add docs.

  3. DavidPressman commented on Jun 9, 2023

    @DavidPressman

    This error appeared in my Maui solution after updating Stimulsoft Reports, which includes SixLabors.ImageSharp 3.01 as a dependency. A similar error also occurs for Size. Obviously I've had to revert and will notify Stimulsoft.

  4. JimBobSquarePants commented on Jun 9, 2023

    @JimBobSquarePants
    Member

    Why revert? Just add the exclusions to your csproj.

  5. DavidPressman commented on Jun 10, 2023

    @DavidPressman
  6. JimBobSquarePants commented on Jun 10, 2023

    @JimBobSquarePants
    Member

    Please rename your conflicting classes to remove such conflicts. Thank you.

    Yeah sure, I'll get right to that.... 🙄

    Hold tight while I make a massive breaking change to a library with 57 million downloads because you can't make a 5-line change to a csproj file.

  7. tocsoft commented on Jun 10, 2023

    @tocsoft
    Member

    Actually, in my own code, I added the proper namespace prefixes to my uses of Color and Size. However, I also use the Microsoft's Community Toolkit to generate observable objects in my partial classes. Any code it generates referring to Color now fails with the error. Please rename your conflicting classes to remove such conflicts. Thank you. David Pressman

    To be fair ImageSharp pre-dates Maui so you could argue that they should renamed thiers.

    But on a more helpfull(ish) note I would have to argue that the really issue here seems to stem from the Microsoft's Community Toolkit being buggy and generating bad/fragile code, auto generated code (in my opinon) should really always be generated referencing types absolutly i.e global::SixLabors.ImageSharp.Color etc. That way the generated code can never be ambiguous... yes the generated code is verbose but what does the compiler care.

  8. DavidPressman commented on Jun 10, 2023

    @DavidPressman
  9. tocsoft commented on Jun 10, 2023

    @tocsoft
    Member

    that would be the comment #2466 (comment) (first comment on the original post), which points to the relevent discussion #2381 where I added the csproj code needed fro overriding the implicit usings

  10. DavidPressman commented on Jun 10, 2023

    @DavidPressman
  11. bijington commented on Jun 11, 2023

    @bijington

    But on a more helpfull(ish) note I would have to argue that the really issue here seems to stem from the Microsoft's Community Toolkit being buggy and generating bad/fragile code, auto generated code (in my opinon) should really always be generated referencing types absolutly i.e global::SixLabors.ImageSharp.Color etc. That way the generated code can never be ambiguous... yes the generated code is verbose but what does the compiler care.

    I would agree that this sounds like the source generator code from the .NET Community Toolkit has a bug in it if it cannot handle conflicting types. Has anyone raised this as an issue with the toolkit?

  12. DavidPressman commented on Jun 12, 2023

    @DavidPressman

    This work-around, found elsewhere in the now closed issue 2381 mentioned above, does work when added into the .csproj file:





    As to why it is needed, one might read that issue.
    The reasons why SixLabors chose to add the cause may be well-justified and fully thought out.

    I have received various responses from the SixLabors author about my earlier comments and did appreciate the later ones.
    Nonetheless, I, too, respectfully agree with the essence of some comments in that thread that the cause is rather surprising and, for at least some of us, not only counter-intuitive but one I would not wish to see repeated in other nuget packages.

  13. JimBobSquarePants commented on Aug 17, 2023

    @JimBobSquarePants
    Member

    From v3.1 onwards the behavior will be reversed and the following will be required to add the usings.

    <UseImageSharp>true</UseImageSharp>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions