Comments (21)
OData WebApi v8 is quite diffrernt from v7. https://github.com/OData/AspNetCoreOData is the the new repo for OData WebApi lib 8.0.0. You can get some infomation and sample code from there.
from aspnetcoreodata.
@jashmehta-qds Yes, please
from aspnetcoreodata.
Can confirm, happened to me too.
The null value comes from request.ODataFeature().PrefixName.
The edmModel that is built was not registered in the OdataOptions.
The built edmModel did not pass the validation as the properties did not allow certain filter operations.
I forked the project and got it to work for my use case. It's however dirty code and not the right place to do these things.
from aspnetcoreodata.
This is my Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<DatabaseContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("sqlConnection"))
);
services.AddControllers();
services.AddOData(opt => opt.AddModel("odata", GetEdmModel()));
services.AddAuthentication();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
private static IEdmModel GetEdmModel()
{
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<tbl1>("tbl1");
builder.EntitySet<tbl2>("tbl2");
return builder.GetEdmModel();
}
I have this issue too. Once [EnableQuery] is on an endpoint I get the following:
System.ArgumentNullException: Value cannot be null. (Parameter 'key')
at System.Collections.Generic.Dictionary2.FindValue(TKey key) at System.Collections.Generic.Dictionary
2.ContainsKey(TKey key)
at Microsoft.AspNetCore.OData.ODataOptions.GetODataServiceProvider(String prefix)
at Microsoft.AspNetCore.OData.Extensions.HttpRequestExtensions.GetSubServiceProvider(HttpRequest request)
at Microsoft.AspNetCore.OData.Query.ODataQueryOptions..ctor(ODataQueryContext context, HttpRequest request)
at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.CreateAndValidateQueryOptions(HttpRequest request, ODataQueryContext queryContext)
at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.ExecuteQuery(Object responseValue, IQueryable singleResultCollection, ControllerActionDescriptor actionDescriptor, HttpRequest request)
at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.OnActionExecuted(ActionExecutedContext actionExecutedContext, Object responseValue, IQueryable singleResultCollection, ControllerActionDescriptor actionDescriptor, HttpRequest request)
at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.OnActionExecuted(ActionExecutedContext actionExecutedContext)
at Microsoft.AspNetCore.Mvc.Filters.ActionFilterAttribute.OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
from aspnetcoreodata.
@trevoirwilliams do you have a repro
from aspnetcoreodata.
I am having the same issue. When using [EnableQuery] to my get methods, I get the same stack trace.
System.ArgumentNullException: Value cannot be null. (Parameter 'key')
at System.Collections.Generic.Dictionary`2.FindValue(TKey key)
at System.Collections.Generic.Dictionary`2.ContainsKey(TKey key)
at Microsoft.AspNetCore.OData.ODataOptions.GetODataServiceProvider(String prefix)
at Microsoft.AspNetCore.OData.Extensions.HttpRequestExtensions.GetSubServiceProvider(HttpRequest request)
at Microsoft.AspNetCore.OData.Query.ODataQueryOptions..ctor(ODataQueryContext context, HttpRequest request)
at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.OnActionExecuting(ActionExecutingContext actionExecutingContext)
at Microsoft.AspNetCore.Mvc.Filters.ActionFilterAttribute.OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
from aspnetcoreodata.
@xuzhg would it be possible if I could share to my repo ?
from aspnetcoreodata.
@jashmehta-qds Yes, please
startup.cs
- Function Get All [EnableQuery]
from aspnetcoreodata.
I had the same error, what I noticed that is different between the working sample project and @jashmehta-qds and my controllers is the get method, in the same it is just Get
[HttpGet]
[EnableQuery]
public IActionResult Get(CancellationToken token)
{
return Ok(_persons);
}
i had something like
[HttpGet]
[EnableQuery]
[SwaggerOperation("GetFiles")]
[SwaggerResponse((int)HttpStatusCode.OK)]
[SwaggerResponse((int)HttpStatusCode.NotFound)]
public IActionResult GetFiles()
{
...
return Ok(Files);
}
I added the ODataRouteHandler
to debug what was happening and the route for GetFiles
was not listed, once i changed it to just Get
it started working.
Does the controller name have to match the model too? Just the difference between CDNFileInfoController
and CDNFileInfoAsyncController
seems to enough to lead to the error.
from aspnetcoreodata.
I am having the same issue. When using [EnableQuery] to my get methods, I get the same stack trace.
System.ArgumentNullException: Value cannot be null. (Parameter 'key') at System.Collections.Generic.Dictionary`2.FindValue(TKey key) at System.Collections.Generic.Dictionary`2.ContainsKey(TKey key) at Microsoft.AspNetCore.OData.ODataOptions.GetODataServiceProvider(String prefix) at Microsoft.AspNetCore.OData.Extensions.HttpRequestExtensions.GetSubServiceProvider(HttpRequest request)
Same issue happened to me. Tried to read all available OData / ASP.NET Core documentation available so far, without success.
Workaround: remove [EnableQuery], but then the OData query extensions are not handled any more.
from aspnetcoreodata.
@trevoirwilliams do you have a repro
Not anymore. I deployed without it.
from aspnetcoreodata.
@trevoirwilliams do you have a repro
Not anymore. I deployed without it.
Does this mean, [EnableQuery] is not working with 8.x by design?
from aspnetcoreodata.
@trevoirwilliams do you have a repro
Not anymore. I deployed without it.
Does this mean, [EnableQuery] is not working with 8.x by design?
That has been my experience. I was even considering implementing the previous version.
from aspnetcoreodata.
@jashmehta-qds "GetAll" is not odata routing convention. So, it maps to the non-odata routing. that's not working.
from aspnetcoreodata.
@MarkZither "Get" is naming convention for OData routing convention.
from aspnetcoreodata.
@AndreasGaus @trevoirwilliams enable query works with the odata routing with edm model.
from aspnetcoreodata.
@AndreasGaus @trevoirwilliams enable query works with the odata routing with edm model.
I use an own EF model with MVC controller for REST (derived from Microsoft.AspNetCore.OData.Routing.Controllers.MetadataController) side by side with an EDM model. The EDM model is only used for the $ extensions for filtering (https://docs.microsoft.com/en-us/dynamics-nav/using-filter-expressions-in-odata-uris) sorting etc.
This mix of our own endpoint model plus OData $ extensions does not work anymore because of the [EnableQuery] triggered exception (GetSubServiceProvider -> Find Value -> Value cannot be null). The answers above direct to an issue with the new endpoint routing concepts in OData 8.x.
We originally decided to go to OData 8.x when .NET 5 migration of our .NET Core 3.1 project has been requested.
Probably we have to drop OData filtering, sorting etc. now and remove OData dependency from our REST based server, because in the near future OData team will not support [EnableQuery] in the same way as in former releases?
from aspnetcoreodata.
enable query works with the odata routing with edm model.
Is there any chance to make it work without edm model ?
I don't use edm model, I spent several days trying to migrate to OData 8 and it's a nightmare.
from aspnetcoreodata.
@kakone https://devblogs.microsoft.com/odata/up-running-w-odata-in-asp-net-6/ this blog may help
from aspnetcoreodata.
in my GetEdmModel() method I used
builder.Singleton<T>("name");
instead of builder.EntitySet<T>, mostly because my model is not an EntityFrameword entity... I build the model dynamically from a Json source, and map it to a POCO object.
from aspnetcoreodata.
I'd close this issue. Please file a new issue if you have further concerns or questions. thanks a lot.
from aspnetcoreodata.
Related Issues (20)
- Instance Annotations for properties with $select query option HOT 1
- Custom FilterBinder doesn't work on actions with querying via ODataQueryOptionParser HOT 7
- It's still not clear how to filter by enum property HOT 7
- How to define `EDM model` that add subquery on control to `OData Endpoint Mapping`? HOT 3
- How do I use the month function of date type in a group query
- WebApiAssembliesResolver class missing causing slow model build HOT 2
- Allow casting Edm.Untyped to a primitive type for `$filter`ing when the other operand is also a primitive HOT 4
- There seems to be an issue with case conversion when using Newtonsoft, I don't know yet if it's just case HOT 5
- Passing a Complex object in the ODATA function HOT 5
- Faulty link generation when creating entities with string key and slashes HOT 1
- NullReference exception generated when using FilterClause.ApplyTo method with open properties in the filter query HOT 2
- Case sensitive issue on ODatadynamic Model HOT 2
- Conflicting routes when using NSwag and OData HOT 6
- Data not loaded correctly in Excel and Power BI Desktop with the use of $expand in OData feed HOT 10
- OData DeepInsert not binding correctly HOT 3
- Strange time zone propagation in the filter HOT 2
- Select query throw an error on a dynamic property dictionary HOT 7
- OData + EfCore Filter dynamic properties HOT 2
- FEATURE REQUEST: be able to conditionally omit properties from response payloads HOT 2
- Missing property error when applying select manually HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aspnetcoreodata.