Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NS2001: False positive for class with protected internal constructor #219

Closed
reduckted opened this issue Apr 9, 2024 · 0 comments · Fixed by #221
Closed

NS2001: False positive for class with protected internal constructor #219

reduckted opened this issue Apr 9, 2024 · 0 comments · Fixed by #221
Labels
bug Something isn't working

Comments

@reduckted
Copy link

When creating a substitute for a class with a protected internal constructor, the diagnostic NS2001 is produced, even though the substitute can be created.

This seems to be a recurrence of #144.

public class Program {
    public static void Main() {
        Tester target = Substitute.For<Tester>(42);
        //              ~~~~~~~~~~~~~~~~~~~~~~~~~~ Could not find accessible constructor.

        Console.WriteLine(target.GetValue());
        // Outputs 42.
    }
}

public class Tester {
    private readonly int _value;

    protected internal Tester(int value) {
        _value = value;
    }

    public int GetValue() {
        return _value;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants