Method parameter reported as removable although it's being used

Hey there,

I just got a code smell reported for a parameter that is in use. But SC thinks I can remove it (“Remove this parameter ‘serviceProvider’, whose value is ignored in the method.”).
I suspect SC has some detection issue due to the parameter’s method used as a method group. Or am I missing sth here?

private static IEnumerable<DbContext> GetAllDbContextInstances(IServiceProvider
 serviceProvider)
{
    var types = GetAllDbContextTypes();
    var instances = types.Select(serviceProvider.GetRequiredService);
    foreach (var instance in instances)
    {
        yield return (DbContext)instance;
    }
}

Message in Context

David

Hi @Velociraptor45!

Thanks for reporting this, I can confirm that it is indeed a false positive. We are already aware of this issue for this specific rule, I’ll make sure to add your post to that discussion.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.