Code Monkey home page Code Monkey logo

Comments (21)

anranruye avatar anranruye commented on May 27, 2024 1

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.

xuzhg avatar xuzhg commented on May 27, 2024 1

@jashmehta-qds Yes, please

from aspnetcoreodata.

lukas-gmuer avatar lukas-gmuer commented on May 27, 2024

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.

lukas-gmuer@2c25162

from aspnetcoreodata.

trevoirwilliams avatar trevoirwilliams commented on May 27, 2024

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.Dictionary2.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.

xuzhg avatar xuzhg commented on May 27, 2024

@trevoirwilliams do you have a repro

from aspnetcoreodata.

jashmehta-qds avatar jashmehta-qds commented on May 27, 2024

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.

jashmehta-qds avatar jashmehta-qds commented on May 27, 2024

@xuzhg would it be possible if I could share to my repo ?

from aspnetcoreodata.

jashmehta-qds avatar jashmehta-qds commented on May 27, 2024

@jashmehta-qds Yes, please
startup.cs

Tax Account controller

  • Function Get All [EnableQuery]

from aspnetcoreodata.

MarkZither avatar MarkZither commented on May 27, 2024

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.

AndreasGaus avatar AndreasGaus commented on May 27, 2024

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 avatar trevoirwilliams commented on May 27, 2024

@trevoirwilliams do you have a repro

Not anymore. I deployed without it.

from aspnetcoreodata.

AndreasGaus avatar AndreasGaus commented on May 27, 2024

@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 avatar trevoirwilliams commented on May 27, 2024

@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.

xuzhg avatar xuzhg commented on May 27, 2024

@jashmehta-qds "GetAll" is not odata routing convention. So, it maps to the non-odata routing. that's not working.

from aspnetcoreodata.

xuzhg avatar xuzhg commented on May 27, 2024

@MarkZither "Get" is naming convention for OData routing convention.

from aspnetcoreodata.

xuzhg avatar xuzhg commented on May 27, 2024

@AndreasGaus @trevoirwilliams enable query works with the odata routing with edm model.

from aspnetcoreodata.

AndreasGaus avatar AndreasGaus commented on May 27, 2024

@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.

kakone avatar kakone commented on May 27, 2024

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.

anranruye avatar anranruye commented on May 27, 2024

@kakone https://devblogs.microsoft.com/odata/up-running-w-odata-in-asp-net-6/ this blog may help

from aspnetcoreodata.

Budsy avatar Budsy commented on May 27, 2024

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.

xuzhg avatar xuzhg commented on May 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.