Meziantou.Analyzer icon indicating copy to clipboard operation
Meziantou.Analyzer copied to clipboard

Do not report MA0155 for method that overrides base method

Open drieseng opened this issue 5 months ago • 1 comments

MA0155 is currently also reported for a method that overrides a method on a base class. When the base class is not under your control, you cannot change its return type of course. Same applies when the method implements an interface, but that is perhaps less easy (less performant) to implement.

I'm not sure if you should fix this issue :-) I only ran into it in our unit tests where we have a base class that defines a protected abstract void Act() method and some concrete classes that test an async method. These concrete test classes decorate the Act() method with the async modifier in order to use await.

In that case, the base class - which invokes the Act() method - cannot await the (in some cases) async Act() method since that method returns void. I think there are two options here:

  • Rename the Act() method to ActAsync and have it return Task.
  • Update overrides of the Act() method to use GetAwaiter().GetResult() to await the async method that it's testing.

I'm sure option 1 is the preferred solution. Neither of these options require changes in the MA0155 rule.

drieseng avatar Sep 02 '24 13:09 drieseng