Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASP.NET ApiVersioning 5.1 Issues #1012

Open
1 task done
akristanto opened this issue Jul 31, 2023 · 9 comments
Open
1 task done

ASP.NET ApiVersioning 5.1 Issues #1012

akristanto opened this issue Jul 31, 2023 · 9 comments

Comments

@akristanto
Copy link

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

@commonsensesoftware
Copy link
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.

@akristanto
Copy link
Author

akristanto commented Jul 31, 2023

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.

@commonsensesoftware
Copy link
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.

@akristanto
Copy link
Author

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

@commonsensesoftware
Copy link
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. 😉

@commonsensesoftware
Copy link
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.

@akristanto
Copy link
Author

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

@commonsensesoftware
Copy link
Collaborator

Cross posting. A repro was provided at:

https://github.com/fannydengdeng/ODataApiVersioning

@commonsensesoftware
Copy link
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.

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

No branches or pull requests

2 participants