Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

AV0004: Invalid API version number

Value
Rule IDAV0004
CategoryUsage
Fix isBreaking

Cause

An API version specified a negative number.

Rule Description

Specifying an API version as a number removes a class of issues, but the number can still be specified as a negative value.

Consider the following code:

[ApiController]
[ApiVersion(-2.0)]
[Route("[controller]")]
public class ExampleController : ControllerBase
{
    [HttpGet]
    public IActionResult Get() => Ok();
}

The text -2.0 is not a valid API version. This would not detected until runtime.

How to Fix Violations

An API version should always be greater than or equal to 0.1. Update the API version to be well-formed.

[ApiController]
[ApiVersion(2.0)]
[Route("[controller]")]
public class ExampleController : ControllerBase
{
    [HttpGet]
    public IActionResult Get() => Ok();
}

When to Suppress Warnings

It is never safe to suppress this rule because a runtime exception will be thrown when the attribute is initialized.