AV0005: Invalid API version year
| Value | |
|---|---|
| Rule ID | AV0005 |
| Category | Usage |
| Fix is | Breaking |
Cause
An API version expressed an invalid year.
Rule Description
When an API version is expressed as a date, the specified year must be valid.
Consider the following code:
[ApiController]
[ApiVersion(10_000, 1, 1)]
[Route("[controller]")]
public class ExampleController : ControllerBase
{
[HttpGet]
public IActionResult Get() => Ok();
}
The year 10_000 is not a valid API version. The year must be between 1 and 9999. This would not detected until
runtime.
How to Fix Violations
Update the API version to be well-formed.
[ApiController]
[ApiVersion(2026, 1, 1)]
[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.