Search code examples
c#code-analysis

False positive for CA1801 in Release config only


My method reads as follows.

public static void Debug(this Logger logger, string message)
{
    logger.Debug(() => message);
}

When I run code analysis with Debug config, I get no warning.

When I run code analysis with Release config, I get:

CA1801 Review unused parameters Parameter 'message' of 'CommonExtensions.Debug(this Logger, string)' is never used. Remove the parameter or use it in the method body. FakeItEasy CommonExtensions.cs 101

and

CA1801 Review unused parameters Parameter 'logger' of 'CommonExtensions.Debug(this Logger, string)' is never used. Remove the parameter or use it in the method body. FakeItEasy CommonExtensions.cs 101

This is clearly wrong. I am using both parameters in the method body. If I remove either of the parameters then the code does not compile.

Has anyone else experienced anything similar? Have I discovered a bug in code analysis?

(I am using the same ruleset under both configurations.)


UPDATE

The Logger.Debug() signature is as follows:

[Conditional("DEBUG")]
public abstract void Debug(Func<string> message);

Solution

  • As per the Q update, Logger.Debug() has the Conditional attribute set and this is the cause.