-
Notifications
You must be signed in to change notification settings - Fork 711
Error: "Cannot find the services container for route" when using MapVersionedODataRoute #553
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
Apologies for the delayed response. This type of configuration will not work with API Versioning and OData. You cannot use the default OData routing conventions. API Versioning has to replace or extend the default routing conventions to make things work. There are, however, hooks to extend or add additional routing conventions via a callback in the route registration. You don't appear to need this, so I would just remove it. Based on the configuration you've shared, it appears that if you remove that, the rest of it should work. I hope that helps. |
Hello commonsensesoftware, Thanks for your support! Can you specify which section you propose that I remove from the above configuration? |
Should definitely remove this: containerBuilder.AddService<IEnumerable<IODataRoutingConvention>>(
Microsoft.OData.ServiceLifetime.Singleton,
sp => ODataRoutingConventions.CreateDefaultWithAttributeRouting(routeName, routeBuilder)); Start with that and if it still doesn't work, we can move on to what else needs to change. |
OK, with those lines removed, it looks like the behavior is the same. I can still reach routes/EntitySets that are in the EdmModel. But when I try to browse to a non-existent route/EntitySet I get the exception from above: Seems like any bogus route will cause that exception. For example: |
I can try to build a reproducing sample project without my company's specifics if you think that would help. |
Repros are always helpful. The simpler the better. |
Here is a simplified repro. There are 2 launch settings.
Thank you for your time looking into this. Best Regards. |
@commonsensesoftware I am getting this same error as well and I have no idea what I am doing wrong or what the exception means. I wrote a detailed Stack Overflow question on it so I will delegate to that here: I am trying to setup a new .NET Core 3.1 API with OData. I have a working .NET Core API in 2.2 with OData, so I am going off of that one. I am using three OData specific nuget packages: Microsoft.AspNetCore.OData v7.3.0, Microsoft.AspNetCore.OData.Versioning v4.1.1 and Microsoft.AspNetCore.OData.Versioning.ApiExplorer v4.1.1. I keep getting the following response when I send a GET request to my controller:
Note I have the requirement that the API needs to be versioned. I am not sure if versioning has something to do with this error, but the old .NET Core 2.2 API that I have uses OData versioning as well. Does anyone know what the services container is for a route? I setup my project similar to https://devblogs.microsoft.com/odata/experimenting-with-odata-in-asp-net-core-3-1/. Here is the ConfigureServices
Here is the Configure
Here is the extension method
Here is the controller
|
@nfgallimore it doesn't look like the OData mappings match any supported configuration. Your EDM has a MyObject entity set, but that's not the controller you've shown (and I would have expected it to be MyObjects). The AlternateIdsController isn't for an entity set nor seems to provide any unbound functions or actions. Finally, you can thank the OData team for continuing to have their own attributes which are completely different in meaning and use from the standard routing attributes. You need to use The Swagger/OpenAPI example here for OData has a number of different scenarios covered, including:
Start with that and then we can move on to other potential issues. |
I named it ObjectController and setup the EdmModel to map to Objects "Objects" in GetEdmModel() vs "ObjectController" in Controller class name. I just figured that out, thank you sir. |
Regarding the repro I posted, pls let me know in case it does not work. If there's anything else I could do lmk as well. Thanks. |
I can confirm that this is, in fact, a bug. The OData team occasionally changes the behavior of the internal mechanics and it isn't always hard to catch. API Versioning uses a a special catch-all route for OData to handle the scenario when a requested version doesn't match anything. This behavior will result in the built-in ODataPathRouteConstraint attempting to create a request container. No root container is configured for this route since it doesn't actually do anything. It will result in the appropriate 400 or 404 instead of a 500. Since the container is now required, but not registered, it blows up with 500. As far as I can tell, this only happens when you request an entity that doesn't exist. The fix is forthcoming and will go into the next path. Thanks. |
One more question on this thread. It's been a year (yikes - sorry for that) and I noticed this issue is mentioning ASP.NET Core 2.2. Has everyone since moved to 3.1? I hope most people have moved forward. There's a massive set of changes for OData coming to address all the fixes, including Endpoint Routing. If I have break out specific changes for for 2.2, I'll have do it separately. It probably won't come fast either - unfortunately. Multiple, parallel branches are difficult to maintain. If anyone says the really need 2.2 support, I'll track it separately. Thanks. |
Hi, I will move onto 3.1 sometime. From my perspective, please do what's best for the long term. Thank you greatly for your support! |
Hello, I'm using the ASP.NET Core 2.2 and OData. I'm using the following setup in which I create the EdmModel dynamically by looking at the user's claims. Based on the claims, I add a EntitySet A or EntitySet B for example.
When I browse to the controller for EntitySet A and the user doesn't have the claim for it,
I get the following exception when I use the
MapVersionedODataRoute
. I don't get the exception if I use the OData routebuilder methodMapODataServiceRoute(...);
which returns 404 as expected instead.Perhaps my setup is not supported or I misconfigured something? Thanks for your time.
Exception Message:
StackTrace
Startup.cs
Nuget package versions:
The text was updated successfully, but these errors were encountered: