False positive on C#:S3928:Parameter names used into ArgumentException?

Hello Andrei,

I can only imagine the challenges you guys have to make these rule fit all cases everybody is presenting. :slight_smile:

But… in this case I think it should be about the scope of the variable. The example I have given, the scope is valid and thus the nameof(xxx) should also be considered as valid. At least visual studio says it is fine.

I’m curious about your comment of passing the Action around in respect of the example I have given you. Could you provide me with an example with what you are thinking about? (Maybe I’m on the wrong thinking-path)

And what if we would write the code like this? things is still captured here.

  public void DoSomething(Guid[] things)
    {
        Action action = () =>
        {
            if (things == null)
            {
                throw new ArgumentNullException(nameof(things));
                throw new ArgumentNullException("things");
            }
        };
        WithExceptionHandling(action);
    }

Best regards,
Freddy Groen