Skip to content

Latest commit

 

History

History
67 lines (51 loc) · 1.52 KB

ASP005.md

File metadata and controls

67 lines (51 loc) · 1.52 KB

ASP005

Syntax error in parameter

Topic Value
Id ASP005
Severity Warning
Enabled True
Category AspNetCoreAnalyzers.Routing
Code AttributeAnalyzer

Description

Syntax error in parameter.

Motivation

[HttpGet(""api/orders/id:int}"")]
public IActionResult GetId(int id)
{
    return this.Ok(id);
}

In the above code the opening curly brace for the parameter is missing.

How to fix violations

Use the code fix of fix the syntax manually. The code in the example should be:

[HttpGet(""api/orders/{id:int}"")]
public IActionResult GetId(int id)
{
    return this.Ok(id);
}

Configure severity

Via ruleset file.

Configure the severity per project, for more info see MSDN.

Via #pragma directive.

#pragma warning disable ASP005 // Syntax error in parameter
Code violating the rule here
#pragma warning restore ASP005 // Syntax error in parameter

Or put this at the top of the file to disable all instances.

#pragma warning disable ASP005 // Syntax error in parameter

Via attribute [SuppressMessage].

[System.Diagnostics.CodeAnalysis.SuppressMessage("AspNetCoreAnalyzers.Routing", 
    "ASP005:Syntax error in parameter", 
    Justification = "Reason...")]