The parameter is not declared in the argument list (help wanted)

Hi,

We have added c# code below to our project, and this keeps reporting this error:

Code Smell: The parameter name 'reasonCode' is not declared in the argument list.

So this is probably true, but how can we fix it?

A little help would be appreciated!

static string AsCode(ReasonCode reasonCode) =>
    reasonCode switch
    {
      ReasonCode.Unknown => "0",
      ReasonCode.NotFurtherSpecified => "NotSpecified",
      ReasonCode.SemanticError => "Semantic",
      ReasonCode.UnknownAccount => "Unknown Account",
      ReasonCode.Ok => "Ok",
      ReasonCode.OkWithRemarks => "Ok with remarks",
      _ => throw new ArgumentException("invalid enum value", nameof(reasonCode)),
   };

Hello @arjanvanbekkum,

Your code seems valid and the code smell should not be reported in this case. Unfortunately, I’m not able to reproduce the issue.

  • What version of SonarLint or C# Analyzer are you using?
  • Can you create a minimal project reproducing the issue and share it with us?

Thanks
Pavel

1 Like

hi @Pavel_Mikula,

We are using SonarCloud to analyze our project.

I added a screenshot from the sonar cloud containing the original code.

I’m sorry to say I haven’t got a simple project to reproduce the issue

Best,
Arjan

Hi @arjanvanbekkum,

I’ve tried to create a simple project and I cannot reproduce the issue on SonarCloud. See:
https://sonarcloud.io/code?id=CommunityRepro_26601&selected=CommunityRepro_26601%3ARepro.cs

I also created second occurrance with variable code to see that the rule is active and works.

Please try to create simple reproducer and share it with us. There might be something specific that we don’t see so we cannot fix it.

For quick verification (without SonarCloud), you can install SonarLint extension that also contains the C# analyzer and shows you the issues directly in the Visual Studio.

Thanks
Pavel