The request does not support the API version

Some time back Microsoft released a library that helped in implementing version of .Net Core API. At that time, you were referencing Microsoft.AspNetCore.Mvc.Versioning. A simple use of this library is as below.

[ApiController]
[ApiVersion("1.0")]
[ApiVersion("4.0")]
public abstract class BaseApiController:ControllerBase
{
}
The above code snippet is from a project that I work on. This code implies that the .Net Core Web Api will support version 1.0 and 4.0. If you use the old NuGet package, version 5, with .Net 7 project, it ends up throwing following error when you call the API.
The HTTP resource that matches the request URI 'https://localhost:44358/api/v4.0/system/doit' does not support the API version '4.0'

If you are going to use API versioning in .Net 7 project, remove the old Microsoft.AspNetCore.Mvc.Versioning Nuget package and install the latest Asp.Versioning.Http Nuget package. Notice that namespace has changed from Microsoft to Asp. Most important that you will notice is that this version of package requires .Net 7 framework. After you add reference to this new package, the code snippet can be changed to as below.

[ApiController]
[ApiVersion(1.0)]
[ApiVersion(4.0)]
public abstract class BaseApiController:ControllerBase
{
}

An extension has been added to provide the version number as double data type in addition to string type.

Updated package shall help you in getting rid of the error complaining about unsupported API version.

Search

Social

Weather

17.6 °C / 63.6 °F

weather conditions Clear

Monthly Posts

Blog Tags