Repository navigation
Ambiguous reference between 'Microsoft.Maui.Graphics.Color' and 'SixLabors.ImageSharp.Color' #2466
Description
Activity
See #2381
Reacted by Mike RowleyI'll keep this open as I want to track adding a single key to remove usings and add docs.
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.
Why revert? Just add the exclusions to your csproj.
Reacted by Nobuyuki Iwanaga, aetos, kurema and Fuchsium- 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…________________________________ From: James Jackson-South ***@***.***> Sent: Friday, June 9, 2023 4:36 PM To: SixLabors/ImageSharp ***@***.***> Cc: DavidPressman ***@***.***>; Comment ***@***.***> Subject: Re: [SixLabors/ImageSharp] Ambiguous reference between 'Microsoft.Maui.Graphics.Color' and 'SixLabors.ImageSharp.Color' (Issue #2466) Why revert? Just add the exclusions to your csproj: — Reply to this email directly, view it on GitHub<#2466 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AEUSP5X6FTDTS5J7INAUBVLXKOCLHANCNFSM6AAAAAAYPPPZ3I>. You are receiving this because you commented.Message ID: ***@***.***>
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.
Reacted by kurema, Kevin Preller and FuchsiumReacted by Glenn F. Henriksen, Tieson Trowbridge, Petar Tasev and mark-at-tusksoftActually, 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.Coloretc. That way the generated code can never be ambiguous... yes the generated code is verbose but what does the compiler care.Reacted by Glenn F. Henriksen, Günther Foidl, Mike Rowley, Matthew Malkin and mark-at-tusksoft- I appreciate that comment much more. You may haver a point the Community Toolkit folks could benefit from. As to the five lines to add to a .csproj, somehow those did not reach me. Would you mind, please, repeating them in any further reply and I'll give them a try? Thank you. David Pressman…________________________________ From: Scott Williams ***@***.***> Sent: Saturday, June 10, 2023 8:22 AM To: SixLabors/ImageSharp ***@***.***> Cc: DavidPressman ***@***.***>; Comment ***@***.***> Subject: Re: [SixLabors/ImageSharp] Ambiguous reference between 'Microsoft.Maui.Graphics.Color' and 'SixLabors.ImageSharp.Color' (Issue #2466) 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. — Reply to this email directly, view it on GitHub<#2466 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AEUSP5RPBWM3GUCOFFHAFXLXKRRILANCNFSM6AAAAAAYPPPZ3I>. You are receiving this because you commented.Message ID: ***@***.***>
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- Thank you. DP…________________________________ From: Scott Williams ***@***.***> Sent: Saturday, June 10, 2023 12:36 PM To: SixLabors/ImageSharp ***@***.***> Cc: DavidPressman ***@***.***>; Comment ***@***.***> Subject: Re: [SixLabors/ImageSharp] Ambiguous reference between 'Microsoft.Maui.Graphics.Color' and 'SixLabors.ImageSharp.Color' (Issue #2466) that would be the comment #2466 (comment)<#2466 (comment)> (first comment on the original post), which points to the relevent discussion #2381<#2381> where I added the csproj code needed fro overriding the implicit usings — Reply to this email directly, view it on GitHub<#2466 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AEUSP5WPWQXFZMGLGYXOZR3XKSPB3ANCNFSM6AAAAAAYPPPZ3I>. You are receiving this because you commented.Message ID: ***@***.***>
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.Coloretc. 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?
Reacted by kuremaThis 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.Reacted by Imre PühvelFrom v3.1 onwards the behavior will be reversed and the following will be required to add the usings.
<UseImageSharp>true</UseImageSharp>
Reacted by Kevin Preller
Prerequisites
DEBUGandRELEASEmodeImageSharp 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