You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have inherited a .NET 6 Web API project utilising OData and the Asp.Versioning packages. The versioning functionality was not 100% correct, and now that the project is required for more regular usage, I want to implement the versioning correctly.
The issue I am hitting is this runtime exception:
Attribute routes with the same name 'odata/v{version:apiVersion}/Parts' must have the same template: Action: '...v2.Controllers.PartsController.Get' - Template: 'odata/v{version:apiVersion}/Parts/odata/v{version:apiVersion}/Parts' Action: '...v2.Controllers.PartsController.Get' - Template: 'odata/v{version:apiVersion}/Parts' Action: '...v1.Controllers.PartsController.Get' - Template: 'odata/v{version:apiVersion}/Parts' Action: '...v1.Controllers.PartsController.Get' - Template: 'odata/v{version:apiVersion}/Parts'
My controllers look like:
namespace ...Api.Versions.v1.Controllers
{
[ApiExplorerSettings(GroupName = "v1")]
[ApiVersion("1")]
[Route("odata/v{version:apiVersion}/[controller]")]
public class PartsController : ODataController
{
[Produces("application/json")]
[EnableQuery]
[HttpGet]
public async Task<IQueryable<Part>> Get()
{
...
}
}
}
and
namespace ...Api.Versions.v2.Controllers
{
[ApiExplorerSettings(GroupName = "v2")]
[ApiVersion("2")]
[Route("odata/v{version:apiVersion}/[controller]")]
public class PartsController : ODataController
{
[Produces("application/json")]
[EnableQuery]
[HttpGet]
public async Task<IQueryable<Part>> Get()
{
...
}
}
}
I've managed to get past the exception by removing the RouteAttribute from my controllers, but my endpoints are being duplicated in the OData route debug page:
I have inherited a .NET 6 Web API project utilising OData and the Asp.Versioning packages. The versioning functionality was not 100% correct, and now that the project is required for more regular usage, I want to implement the versioning correctly.
The issue I am hitting is this runtime exception:
My controllers look like:
and
My Startup.cs has the following configuration:
and my EDM configuration is as follows:
Right now there is no difference between models for v1 and v2, this is purely to test functionality.
I'm trusting that the above configuration is automatically registered for DI as per the last section on this page: https://github.com/dotnet/aspnet-api-versioning/wiki/OData-Model-Configurations
I feel like there is some small piece of config that I've missed, but struggling to find what that might be.
The text was updated successfully, but these errors were encountered: