Skip to content

CA2263 fix incorrectly drops all parameters after 'type' when 'params' follows #7806

Description

@kindermannhubert

CA2263: Prefer generic overload when type is known

When the non-generic overload has (Type type, params T[]? args) and the generic overload has (params T[]? args), the fixer removes the typeof(...) argument but also incorrectly strips all remaining arguments instead of preserving them.

Repro:

using System;

public class Demo
{
    public void Run()
    {
        var activator = new Activator();

        // CA2263 fixer converts this to 'activator.Create<MyClass>()' dropping "hello" and "world" arguments
        _ = (MyClass)activator.Create(typeof(MyClass), "hello", "world");
    }
}

public class MyClass
{
    public MyClass(string[]) { }
}

public class Activator
{
    public T Create<T>(params string[]? args) => default!;
    public object Create(Type type, params string[]? args) => default!;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions