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

error CS0111: Type 'SomeType' already defines a member called 'Equals' with the same parameter types #864

Closed
jlaanstra opened this issue Jun 10, 2021 · 7 comments · Fixed by #1181
Assignees
Labels
bug Something isn't working
Milestone

Comments

@jlaanstra
Copy link
Collaborator

jlaanstra commented Jun 10, 2021

Describe the bug
CsWinRT generates duplicate Equals methods if the underlying type in the WInMD already has an Equals() method with itself as the type parameter

To Reproduce
Create a C++WinRT component with a type that has an Equals method with itself as the equator. For example:

    runtimeclass SomeType
    {
        SomeType();

        Boolean Equals(SomeType someType);
    };

Pass the WinMD to CsWinRT.

Expected behavior
No error.

Version Info
CsWinRT 1.2.6

@jlaanstra jlaanstra added the bug Something isn't working label Jun 10, 2021
@angelazhangmsft
Copy link
Collaborator

We should investigate the built-in support behavior in .NET Native/.NET Core to see what they do

@angelazhangmsft angelazhangmsft added this to the Release 1.2.8 milestone Jun 10, 2021
@angelazhangmsft angelazhangmsft self-assigned this Jun 10, 2021
@angelazhangmsft
Copy link
Collaborator

With existing built-in .NET support for WinRT, default behavior for ToString, Equals(Object), and GetHashCode methods is provided for C# WinRT components. According to these docs, Windows Runtime classes that are written in C# or Visual Basic can override the Equals(Object) method overload.

@Scottj1s - is it possible to define/override the Equals method from a C++/WinRT component that is projected into C#/.NET 5?

@angelazhangmsft
Copy link
Collaborator

angelazhangmsft commented Jun 23, 2021

Looking into the existing .NET Native support:

If we have a C++/WinRT component with the following definition:

runtimeclass Class
    {
        Class();
        Boolean Equals(Class c);
    }

Consuming this component from a .NET Native (UWP) C# application, I see two Equals methods (overloaded):

public bool Equals(Class c); // in my RuntimeComponent
public virtual bool Equals(Object obj); // in System.Runtime - this method also appears if I don't define Equals in my C++/WinRT component

@angelazhangmsft angelazhangmsft removed their assignment Jun 23, 2021
@jlaanstra
Copy link
Collaborator Author

jlaanstra commented Jul 7, 2021

It sounds like CsWinRT should probably not auto-generate the implementation of IEquatable<SomeType>. Thoughts? /cc @Scottj1s who added this in #249

@angelazhangmsft
Copy link
Collaborator

CsWinRT should ensure the IEquatable pattern of 5 methods is enforced, picking up any methods that the runtime component implements.

@angelazhangmsft angelazhangmsft modified the milestones: Release 1.3.2, Future Jul 20, 2021
@angelazhangmsft angelazhangmsft added the pri-2 Non-critical bugs/acceptable workaround label Jul 20, 2021
@angelazhangmsft angelazhangmsft modified the milestones: Future, Release 1.3.7 Sep 9, 2021
@angelazhangmsft angelazhangmsft removed the pri-2 Non-critical bugs/acceptable workaround label Sep 22, 2021
@Corillian
Copy link

I just ran into this problem 😭.

@pontin-pdftron
Copy link

Same problem here.
We have an old component in C++/CX which overrides Equals and when migrating to C++/WinRT got the same issue.

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.

5 participants