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

CA1067 on C# record implementing a VB.NET interface #2172

Open
enrij opened this issue Apr 22, 2024 · 0 comments
Open

CA1067 on C# record implementing a VB.NET interface #2172

enrij opened this issue Apr 22, 2024 · 0 comments

Comments

@enrij
Copy link

enrij commented Apr 22, 2024

Hi,

I'm experiencing a curious behavior using dotnet format --verify-no-changes command and I also managed to reproduce it in a new project from scratch using .NET core 8 (version 8.0.201).

Take the following C# record definition as reference

public record MyRecord(string A, string B, long C);

if you create an interface in the same C# project and implement it in the record, dotnet format works like a charm

public interface IMyInterface
{
    string A { get; }
    string B { get; }
    long C { get; }
} 

public record MyRecord(string A, string B, long C) : IMyInterface;`

BUT (🍑)... If the same interface comes from another class library project created using VB.NET

Public Interface IMyInterfaceVB
    ReadOnly Property A As String
    ReadOnly Property B As String
    ReadOnly Property C As Long
End Interface

dotnet format --verify-no-changes now fails throwing a warning

warning CA1067: Type DotnetFormatCA1067Bug.MyRecord should override Equals because it implements IEquatable

and dotnet format effectively tries to implement Equals method on the record

public record MyRecord(string A, string B, long C) : IMyInterfaceVB
{
    public override bool Equals(object obj)
    {
        return Equals(obj as MyRecord);
    }
}

Am I missing something? 🤔

For reference:

  • dotnet build doesn't raise any warning about CA1067 even using the VB.NET interface
  • I'm currently using <AnalysisLevel>latest-recommended</AnalysisLevel> in my projects
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant