-
Notifications
You must be signed in to change notification settings - Fork 711
Updating to Microsoft.AspNetCore.Mvc.Versioning 4.2 causes Exception #694
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
Comments
This is essentially the same configuration it was built with. What is the |
I'm probably having the exact same issue. This is my stack trace:
I was migrating the project to Here is the list of installed packages for the solution:
Let me know if you need more info! Thanks! |
I have the same issue in a asp.net core 3.1 project with the version 4.2.0. ApiVersionLinkGenerator is registered as LinkGenerator and it has a LinkGenerator constructor parameter - which makes it circular, or did i miss something? |
@bojanmisic unless you are using the preview version, @jonasaebersold - yes, you missed something 😉 . ASP.NET Core already registers a LinkGenerator implementation by way of DefaultLinkGenerator.cs. There are two systemic issues. First, this class is All, Can anyone share their startup configuration for service registration? If you're seeing this behavior, then 2 things are likely true:
Order is a bit tricky and, in general, should not matter, but in this specific combination, the URL segment method requires that the core MVC services have been registered because that's where the default LinkGenerator is registered. I suspect this is the case. This was hit in the RC, but I thought I had fixed it for good. =/ The good news is, that if I'm correct, then this is something you can easily fix in your configuration. If confirmed, I should be able to repro the scenario. At that time, I'll promote this to bug to be fixed in the next patch, but at least you'll have a lasting workaround. At least in my mind, MVC should always logically be the first set of services registered. |
@commonsensesoftware Thanks for your response. I tried to create a small sample project - and it worked like a charm. So i added more stuff from our project and after all, in my case it's the "AddOData" extension method. If the method is called before "AddApiVersioning", it's not working. I add a sample. If AddOData is called before, the resolved LinkGenerator is of type ApiVersionLinkGenerator, and the other way the type is ODataEndpointLinkGenerator. We use OData in our project to use filter expressions. With the version 4.1.1, the order doesn't matter. But I'm not sure, if the bug comes from the OData package or the ApiVersioning. |
@jonasaebersold thanks for the repro. As I suspected, this seems to be caused by service registration order. Things are even messier with OData because it registers it's own ODataEndpointLinkGenerator, which is yet again
For clarity, the following should be your service registration as it relates to API versioning: services.AddControllers(); // or services.AddMvcCore()
services.AddApiVersioning();
services.AddOData().EnableApiVersioning(); // if using OData
services.AddODataApiExplorer(); // if using OData
// services.AddVersionedApiExplorer(); // if NOT using OData
// TODO: remaining setup Every API Versioning sample project is setup this way and all wiki documentation also show it that way. I'll investigate further in to ensuring that an exception is not thrown; however, you should aware that if you do version by URL segment or intend to (but please don't), then you'll want to register things in the expected sequence. If you don't, you may see that URL generation is wrong if you do not explicitly provide the API version route value. As I recall, in the of case of OData, it does not currently consider other ambient route values so link generation will be wrong in responses. |
I know it's been a long time, but here's a quick update on this issue. Registering OData first causes a couple of bugs. Issue 1The OData implementation replaces the Issue 2This was much, much harder to track down. The short version is that despite OData supporting Endpoint Routing, it still uses
The very reason that Service order registration is not supposed to matter, but it can have significant side effects in this case. Registering things in a sensible order will help, but I believe I've devised a way for people to avoid this landmine in the future. This should be a non-issue in OData 8+, but that remains to be seen. Expect the fix in the next release. Until then, the recommendation is to register things the order provided by the examples. |
Uh oh!
There was an error while loading. Please reload this page.
Preconditions:
Microsoft.AspNetCore.Mvc.Versioning: 4.1.1
Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer: 4.1.1
.NET Core 3.1
Extra Packages:
Microsoft.AspNetCore.Odata: 7.5.1
Microsoft.AspNetCore.OData.Versioning: 4.1.1
Microsoft.AspNetCore.OData.Versioning.ApiExplorer: 4.1.1
Description:
When updating to Microsoft.AspNetCore.Mvc.Versioning V4.2 my application stops working with the following: Exception thrown: 'System.AggregateException' in Microsoft.Extensions.DependencyInjection.dll
Am I missing something somewhere?
The text was updated successfully, but these errors were encountered: