How to ignore dotnet annotations when checking for duplicated code?

Template for a good new topic, formatted with Markdown:

  • ALM used: Azure DevOps
  • CI system used: Azure DevOps
  • Languages of the repository: C#

So, we have a project configured to break the gate if more than 5% of the new code is duplicated. We created a simple pull request that adds a couple ProducesResponseType annotations to a method, for documentation purpose (Swagger generation):

        [ProducesResponseType((int)HttpStatusCode.NotFound, Type = typeof(MessageResult))]
        [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(MessageResult))]
        public async Task<IActionResult> HandleGetData(

We also have numerous other methods in the same file, that use the same kind of annotations. The problem here is that Sonar broke the gate as the two new ProduceResponseType were seen as duplicated code. And whereas I can easily factorize regular code to avoid duplications, annotations like that can seldom be factorized.

Is there any way to tell Sonar to ignore annotations when checking for duplicated code?

Hi @marcl


I’ll take this point to discuss internally.

1 Like