Description
Rule S3241 ("Change return type to 'void'; not a single caller uses the returned value") produces a false positive for private extension methods that return their this parameter type, following the standard Fluent/convention API builder pattern.
Reproducer
public static class ServiceCollectionExtensions
{
private static IServiceCollection AddFoo(this IServiceCollection services)
{
return services;
}
}
Expected
No warning- the method follows the well-known fluent builder pattern (returning the this type).
Actual
warning S3241: Change return type to 'void'; not a single caller uses the returned value.
Analysis
The rule should suppress this diagnostic when:
- The method is an extension method (has this parameter), AND
- The return type matches the this parameter type
These methods follow the same convention as all ASP.NET Core IServiceCollection / IApplicationBuilder extensions. Changing to void would break the fluent chaining pattern and prevent callers from composing calls inline. The fact that no current callers chain off the return value is by design, the return type exists for consistency, future use, and to follow the ecosystem convention.
Product and Version
10.27.0.140913
Description
Rule S3241 ("Change return type to 'void'; not a single caller uses the returned value") produces a false positive for private extension methods that return their this parameter type, following the standard Fluent/convention
APIbuilder pattern.Reproducer
Expected
No warning- the method follows the well-known fluent builder pattern (returning the this type).
Actual
warning S3241: Change return type to 'void'; not a single caller uses the returned value.
Analysis
The rule should suppress this diagnostic when:
These methods follow the same convention as all ASP.NET Core
IServiceCollection/IApplicationBuilderextensions. Changing tovoidwould break the fluent chaining pattern and prevent callers from composing calls inline. The fact that no current callers chain off the return value is by design, the return type exists for consistency, future use, and to follow the ecosystem convention.Product and Version
10.27.0.140913