Skip to content

ASP.NET ApiVersioning 5.1 Issues #1012

Closed

Description

@akristanto

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

After upgrading Microsoft.AspNetCore.OData.Versioning and Microsoft.AspNetCore.Mvc.Versioning from 4.1.1 to 5.1.0 and resolving the breaking changes listed here, I found that a couple APIs stopped working.

  • Some action APIs are not able to be found (404) even where some actions within the same controller were working. example:
// {ServiceName}/{EntityName}({key})/{action}
[ODataRoute("({key})/" + Constants.ActionName)]
public IActionResult Action([FromODataUri] string key, ODataActionParameters parameters)
  • Entity relation parameters tagged with [FromODataUri] are empty for both to a single entity and collection. example:
    Expected the passed in guid but found 00000000-0000-0000-0000-000000000000
// {ServiceName}/{EntityName}({key})/Entity/$ref
[HttpPut]
public IActionResult CreateRefToEntity([FromODataUri] Guid key, [FromBody]Uri link)

// {ServiceName}/{EntityName}({key})/Collection/$ref
[HttpPost]
public IActionResult CreateRefToCollection([FromODataUri] Guid key, [FromBody] Uri link)
  • There were also some other issues that were resolved by updating the ODataRoute. example:
    Adding [ODataRoute({key})] resolved null value for key
[AcceptVerbs("POST", "PUT")]
public async Task<IActionResult> Put(int key, [FromBody] Customer customer, ODataQueryOptions<Customer> options)

Are these issues expected after upgrading Microsoft.AspNetCore.OData.Versioning and Microsoft.AspNetCore.Mvc.Versioning from 4.1.1 to 5.1.0? How do we resolve these errors / debug to find the correct URI?

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

6.0.408

Anything else?

ASP.NET Core 6.0

Activity

  1. commonsensesoftware commented on Jul 31, 2023

    @commonsensesoftware
    Collaborator

    A lot has changed in 2.5 years; OData in particular. Since you are upgrading, is there a particular reason you are staying so far behind on 5.1.0? The latest version is 7.0.x. With the exception of some significant bugs, no further work will be done or is planned for 5.x.x.

    There are number of potential causes of the issues you are observing. OData routing behaviors are incredibly inconsistent. Sometimes it only works by convention and other times only with an attribute. I'm not sure I can troubleshoot it from the snippets alone. OData 7.x vs 8.x is quite different. Do you have the world's simplest repro you can share that would highlight the issues? If I at least have the API versioning setup, EDM setup, and controller/action skeletons, I can probably work backward from there.

  2. akristanto commented on Jul 31, 2023

    @akristanto
    Author

    We tested with version 6.0.0 but it requires ASP.NET Core 8.0 which we do not support yet, so we wanted to upgrade to 5.1.0

    I will have to get back to you on the repro.

  3. commonsensesoftware commented on Jul 31, 2023

    @commonsensesoftware
    Collaborator

    Point of order. 6.0.0 requires .NET 6.0 and ASP.NET Core 6.0. It does also multi-target to support .NET Core 3.1 due to the slow update of OData, but that has been dropped in 7.0 because .NET Core 3.1 is out of support. I try to keep the major version numbers inline with ASP.NET Core itself. 7.0, therefore, aligns to .NET 7.0 and ASP.NET Core 7.0. There is no officially supported version for .NET 8.0 and ASP.NET Core 8.0 - yet.

    A repro will be great. Thanks.

  4. akristanto commented on Jul 31, 2023

    @akristanto
    Author

    Sorry, I meant version 6.0.0 requires ASP.NET Core OData 8.0 which we do not support yet

  5. commonsensesoftware commented on Jul 31, 2023

    @commonsensesoftware
    Collaborator

    Ah, gotcha. A great many things were fixed, particularly in routing. If you're stuck on 7.x for the time being, then so be it. Happy to help iron out getting what you have working on 5.1.0 and OData 7.x and/or how to migrate to OData 8.x. 😉

  6. commonsensesoftware commented on Aug 11, 2023

    @commonsensesoftware
    Collaborator

    Curious if were able to get repro going? You might be able to use one of the provided OData examples as the baseline. The OpenAPI example probably has the most complex and comprehensive variation of different OData setups.

  7. akristanto commented on Aug 15, 2023

    @akristanto
    Author

    Sorry, I have not been able to take on this repro yet. This has been put back in priority.

  8. commonsensesoftware commented on Mar 26, 2024

    @commonsensesoftware
    Collaborator
  9. commonsensesoftware commented on Mar 26, 2024

    @commonsensesoftware
    Collaborator

    @fannydengdeng, thanks for the repro. It did identify the First-Chance Exception issue, but it doesn't seem to be related to the other issues.

    @akristanto after reviewing this yet again, I think the issue may simply be a misconfiguration of the route templates. OData has a weird hodgepodge of conventions that you must know and either have to define your actions to match or explicitly configure the route template. My experience has been that neither approach works in their entirety. The documentation is helpful, but it doesn't cover every use case. You almost have to know all of the conventions by heart. If things do not match up, OData does not see it as a route. OData 8.0+ now has a debugging feature to help determine which routes are defined and which ones OData recognizes, but I realize you aren't there - yet.

    I don't need your whole application. If you're able to strip something down to just the parts you're having trouble with, I can probably help fix the route templates. Without a repro, I'm just guessing and trying to simulate the conditions via text. I'd hate to have you try solutions that I don't even know will work. Sometimes getting it working requires fidgeting with the route templates.

    As an alternative, you can try getting something minimal working on your end without API Versioning. I suspect you'll find the routes still don't match, even with API Versioning removed. That may make troubleshooting and dialing in the templates easier. Once you have those working, re-enable API Versioning.

    I hope that helps.

  10. commonsensesoftware commented on Nov 19, 2025

    @commonsensesoftware
    Collaborator

    It's been quite some time. Checking back in. Did this problem ever get solved? Are you really still trying to work on 5.x? I'm trying to determine if this is still worth an investigation. I suspect you'll have better success with more current versions.

  11. commonsensesoftware commented on Dec 27, 2025

    @commonsensesoftware
    Collaborator

    This issue appears to have been resolved or abandoned, but I'm happy to reopen the discussion in the future. It's very unlikely I will go back and service 5.1.x because I don't have the capacity to maintain a bunch of releases in parallel. If this issue still exists in the current release (8.1.x), it should definitely be addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions