AspNetCoreOData
AspNetCoreOData copied to clipboard
oData 8.0.3 with .NET6 reports an error when the query uses $select or $expand
When we execute a query that uses $select or $expand, the request does not return data
Assemblies affected
Microsoft.NET.Sdk.Web
TargetFramework:net6.0
Microsoft.AspNetCore.Mvc.NewtonsoftJson: Version=5.0.12
Microsoft.AspNetCore.OData: Version=8.0.3
Microsoft.AspNetCore.SpaServices.Extensions: Version=5.0.12
Microsoft.OData.Core: Version=7.9.4
Microsoft.OData.Edm: Version=7.9.4
Microsoft.OData.ModelBuilder: Version=1.0.7
Reproduce steps
Create a WEB MVC project that targets Microsoft.NET.Sdk.Web, net6.0, create a query with a $select or $expand
Expected result
It should return data
Actual result
Failed to load response data: No data found for resource with given identifier
Additional detail
We recently migrated our project from net47 to net.5#.0. We upgraded oData to 8.3 and we have a serious problem
Queries that use $expand, $select do not work anymore, used to work
$expand=fillLevels,sensors&$filter=((deviceName/modelName%20eq%20'Rapidpoint%20500')%20and%20(deviceName/name%20eq%20'Rapidpoint%20500;10001'))%20and%20(IsActive%20eq%20true)&$top=10&$orderby=LocationSortOrder%20asc&$count=true $select=errorId&$filter=(deviceIdent%20eq%20721)%20and%20((familyName%20eq%20'Bloodgas')%20and%20(deviceName/modelName%20eq%20'Rapidpoint%20500'))%20and%20(eventTime%20ge%202021-10-31T00:00:00.000Z%20and%20eventTime%20lt%202021-11-01T00:00:00.000Z)&$orderby=eventTime%20desc,errorId%20asc
Queries that use $filter, $orderby, $top, $apply are working perfect
$filter=measurementTime%20ge%202021-10-24T00:00:00.000Z%20and%20measurementTime%20lt%202021-11-01T00:00:00.000Z&$top=30&$orderby=measurementSortOrder%20asc,measurementTime%20desc&$count=true $apply=filter(measurementTime%20ge%202021-10-24T00:00:00.000Z%20and%20measurementTime%20lt%202021-11-01T00:00:00.000Z)/groupby((lotNumber))
This is how we register oData
services.AddControllers().AddOData(option => { option.Select(); option.Filter(); option.Count(); option.OrderBy(); option.Expand(); option.SetMaxTop(100); option.TimeZone = TimeZoneInfo.Utc; option.AddRouteComponents("odata", GetEdmModel()); option.AddRouteComponents("odata/{workspaceId}", GetEdmModel()); });
@athinadev Can you share with me your call stack or a repro for me to dig more?
The Database access is EF6.
Request URL: http://localhost:5000/odata/DeviceSummaries
Request Payload: $expand=fillLevels,sensors&$filter=IsActive%20eq%20true&$top=30&$orderby=LocationSortOrder%20asc&$count=true
Request Payload: $select=deviceLocation,familyName,deviceGroups,deviceName,softwareVersion&$filter=IsActive%20eq%20true
`
Stack trace
23 08:14:06.118 Microsoft.AspNetC I: Executed action RioWeb.Controllers.OData.DeviceSummariesController.Post (RioWeb) in 1606.0278ms
23 08:14:06.118 Microsoft.AspNetC I: Executed endpoint 'RioWeb.Controllers.OData.DeviceSummariesController.Post (RioWeb)'
23 08:14:06.157 RioWeb.Infrastruc E: Exception encountered while handling web API
System.NotSupportedException: Unable to create a constant value of type 'Microsoft.OData.Edm.IEdmModel'. Only primitive types or enumeration types are supported in this context.
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.ConstantTranslator.TypedTranslate(ExpressionConverter parent, ConstantExpression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MemberInitTranslator.TypedTranslate(ExpressionConverter parent, MemberInitExpression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, DbExpression& source, DbExpressionBinding& sourceBinding, DbExpression& lambda)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SelectTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateSet(Expression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.UnarySequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.Convert()
at System.Data.Entity.Core.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable1 forMergeOption) at System.Data.Entity.Core.Objects.ObjectQuery1.<>c__DisplayClass41_0.<GetResults>b__1()
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) at System.Data.Entity.Core.Objects.ObjectQuery1.<>c__DisplayClass41_0.<GetResults>b__0()
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func1 operation) at System.Data.Entity.Core.Objects.ObjectQuery1.GetResults(Nullable1 forMergeOption) at System.Data.Entity.Core.Objects.ObjectQuery1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__31_0()
at System.Data.Entity.Internal.LazyEnumerator1.MoveNext() at Microsoft.AspNetCore.OData.Formatter.Serialization.ODataResourceSetSerializer.WriteResourceSetAsync(IEnumerable enumerable, IEdmTypeReference resourceSetType, ODataWriter writer, ODataSerializerContext writeContext) at Microsoft.AspNetCore.OData.Formatter.Serialization.ODataResourceSetSerializer.WriteObjectInlineAsync(Object graph, IEdmTypeReference expectedType, ODataWriter writer, ODataSerializerContext writeContext) at Microsoft.AspNetCore.OData.Formatter.Serialization.ODataResourceSetSerializer.WriteObjectAsync(Object graph, Type type, ODataMessageWriter messageWriter, ODataSerializerContext writeContext) at Microsoft.AspNetCore.OData.Formatter.ODataOutputFormatterHelper.WriteToStreamAsync(Type type, Object value, IEdmModel model, ODataVersion version, Uri baseAddress, MediaTypeHeaderValue contentType, HttpRequest request, IHeaderDictionary requestHeaders, IODataSerializerProvider serializerProvider) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|30_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker) 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.Policy.AuthorizationMiddlewareResultHandler.HandleAsync(RequestDelegate next, HttpContext context, AuthorizationPolicy policy, PolicyAuthorizationResult authorizeResult) at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at RioWeb.Infrastructure.MagnusHttpResponseMiddleware.Invoke(HttpContext context) in D:\_Dev\.net6.rio.next\RioWeb\Infrastructure\MagnusHttpResponseMiddleware.cs:line 70 at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context) at RioWeb.Infrastructure.MagnusTimeServerMiddleware.Invoke(HttpContext context, IMagnusSettings settings) in D:\_Dev\.net6.rio.next\RioWeb\Infrastructure\MagnusTimeServerMiddleware.cs:line 54 at RioWeb.Infrastructure.MagnusErrorHandler.Invoke(HttpContext context) in D:\_Dev\.net6.rio.next\RioWeb\Infrastructure\MagnusErrorHandler.cs:line 53 23 08:14:06.201 Microsoft.AspNetC E: An unhandled exception has occurred while executing the request. System.InvalidOperationException: Headers are read-only, response has already started. at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpHeaders.ThrowHeadersReadOnlyException() at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpResponseHeaders.Microsoft.AspNetCore.Http.IHeaderDictionary.set_ContentType(StringValues value) at Microsoft.AspNetCore.Http.DefaultHttpResponse.set_ContentType(String value) at RioWeb.Infrastructure.MagnusErrorHandler.HandleExceptionAsync(HttpContext context, Exception exception) in D:\_Dev\.net6.rio.next\RioWeb\Infrastructure\MagnusErrorHandler.cs:line 110 at RioWeb.Infrastructure.MagnusErrorHandler.Invoke(HttpContext context) in D:\_Dev\.net6.rio.next\RioWeb\Infrastructure\MagnusErrorHandler.cs:line 64 at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context) 23 08:14:06.209 Microsoft.AspNetC W: The response has already started, the error page middleware will not be executed. 23 08:14:06.209 Microsoft.AspNetC E: Connection id "0HMD8Q04CV53Q", Request id "0HMD8Q04CV53Q:00000009": An unhandled exception was thrown by the application. System.InvalidOperationException: Headers are read-only, response has already started. at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpHeaders.ThrowHeadersReadOnlyException() at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpResponseHeaders.Microsoft.AspNetCore.Http.IHeaderDictionary.set_ContentType(StringValues value) at Microsoft.AspNetCore.Http.DefaultHttpResponse.set_ContentType(String value) at RioWeb.Infrastructure.MagnusErrorHandler.HandleExceptionAsync(HttpContext context, Exception exception) in D:\_Dev\.net6.rio.next\RioWeb\Infrastructure\MagnusErrorHandler.cs:line 110 at RioWeb.Infrastructure.MagnusErrorHandler.Invoke(HttpContext context) in D:\_Dev\.net6.rio.next\RioWeb\Infrastructure\MagnusErrorHandler.cs:line 64 at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Watch.BrowserRefresh.BrowserRefreshMiddleware.InvokeAsync(HttpContext context) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication1 application)
23 08:14:06.209 Microsoft.AspNetC I: Request finished HTTP/1.1 POST http://localhost:5000/odata/DeviceSummaries text/plain 108 - 200 - application/json;+odata.metadata=minimal;+odata.streaming=true 1714.3605ms
52 08:14:06.226 Microsoft.AspNetC I: Request starting HTTP/1.1 POST http://localhost:5000/odata/DeviceSummaries text/plain 102
52 08:14:06.226 Microsoft.AspNetC I: Executing endpoint 'RioWeb.Controllers.OData.DeviceSummariesController.Post (RioWeb)'
52 08:14:06.226 Microsoft.AspNetC I: Route matched with {action = "Post", controller = "DeviceSummaries"}. Executing controller action with signature Microsoft.AspNetCore.Mvc.IActionResult Post() on controller RioWeb.Controllers.OData.DeviceSummariesController (RioWeb).
52 08:14:06.258 Microsoft.AspNetC I: Executing OkObjectResult, writing value of type 'System.Data.Entity.Infrastructure.DbQuery1[[Microsoft.AspNetCore.OData.Query.Wrapper.SelectSome1[[Magnus.DataAccess.Model.Models.DeviceSummary, Siemens.Magnus.DataAccess.Model, Version=5.1100.49.0, Culture=neutral, PublicKeyToken=null]], Microsoft.AspNetCore.OData, Version=8.0.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]'.
52 08:14:06.258 Microsoft.AspNetC I: Executed action RioWeb.Controllers.OData.DeviceSummariesController.Post (RioWeb) in 32.0341ms
52 08:14:06.258 Microsoft.AspNetC I: Executed endpoint 'RioWeb.Controllers.OData.DeviceSummariesController.Post (RioWeb)'
52 08:14:06.300 RioWeb.Infrastruc E: Exception encountered while handling web API
System.NotSupportedException: Unable to create a constant value of type 'Microsoft.OData.Edm.IEdmModel'. Only primitive types or enumeration types are supported in this context.
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.ConstantTranslator.TypedTranslate(ExpressionConverter parent, ConstantExpression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MemberInitTranslator.TypedTranslate(ExpressionConverter parent, MemberInitExpression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, DbExpression& source, DbExpressionBinding& sourceBinding, DbExpression& lambda)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SelectTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.Convert()
at System.Data.Entity.Core.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable1 forMergeOption) at System.Data.Entity.Core.Objects.ObjectQuery1.<>c__DisplayClass41_0.<GetResults>b__1()
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) at System.Data.Entity.Core.Objects.ObjectQuery1.<>c__DisplayClass41_0.<GetResults>b__0()
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func1 operation) at System.Data.Entity.Core.Objects.ObjectQuery1.GetResults(Nullable1 forMergeOption) at System.Data.Entity.Core.Objects.ObjectQuery1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__31_0()
at System.Data.Entity.Internal.LazyEnumerator1.MoveNext() at Microsoft.AspNetCore.OData.Formatter.Serialization.ODataResourceSetSerializer.WriteResourceSetAsync(IEnumerable enumerable, IEdmTypeReference resourceSetType, ODataWriter writer, ODataSerializerContext writeContext) at Microsoft.AspNetCore.OData.Formatter.Serialization.ODataResourceSetSerializer.WriteObjectInlineAsync(Object graph, IEdmTypeReference expectedType, ODataWriter writer, ODataSerializerContext writeContext) at Microsoft.AspNetCore.OData.Formatter.Serialization.ODataResourceSetSerializer.WriteObjectAsync(Object graph, Type type, ODataMessageWriter messageWriter, ODataSerializerContext writeContext) at Microsoft.AspNetCore.OData.Formatter.ODataOutputFormatterHelper.WriteToStreamAsync(Type type, Object value, IEdmModel model, ODataVersion version, Uri baseAddress, MediaTypeHeaderValue contentType, HttpRequest request, IHeaderDictionary requestHeaders, IODataSerializerProvider serializerProvider) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|30_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker) 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.Policy.AuthorizationMiddlewareResultHandler.HandleAsync(RequestDelegate next, HttpContext context, AuthorizationPolicy policy, PolicyAuthorizationResult authorizeResult) at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at RioWeb.Infrastructure.MagnusHttpResponseMiddleware.Invoke(HttpContext context) in D:\_Dev\.net6.rio.next\RioWeb\Infrastructure\MagnusHttpResponseMiddleware.cs:line 70 at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context) at RioWeb.Infrastructure.MagnusTimeServerMiddleware.Invoke(HttpContext context, IMagnusSettings settings) in D:\_Dev\.net6.rio.next\RioWeb\Infrastructure\MagnusTimeServerMiddleware.cs:line 54 at RioWeb.Infrastructure.MagnusErrorHandler.Invoke(HttpContext context) in D:\_Dev\.net6.rio.next\RioWeb\Infrastructure\MagnusErrorHandler.cs:line 53 52 08:14:06.337 Microsoft.AspNetC E: An unhandled exception has occurred while executing the request. System.InvalidOperationException: Headers are read-only, response has already started. at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpHeaders.ThrowHeadersReadOnlyException() at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpResponseHeaders.Microsoft.AspNetCore.Http.IHeaderDictionary.set_ContentType(StringValues value) at Microsoft.AspNetCore.Http.DefaultHttpResponse.set_ContentType(String value) at RioWeb.Infrastructure.MagnusErrorHandler.HandleExceptionAsync(HttpContext context, Exception exception) in D:\_Dev\.net6.rio.next\RioWeb\Infrastructure\MagnusErrorHandler.cs:line 110 at RioWeb.Infrastructure.MagnusErrorHandler.Invoke(HttpContext context) in D:\_Dev\.net6.rio.next\RioWeb\Infrastructure\MagnusErrorHandler.cs:line 64 at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context) 52 08:14:06.337 Microsoft.AspNetC W: The response has already started, the error page middleware will not be executed. 52 08:14:06.337 Microsoft.AspNetC E: Connection id "0HMD8Q04CV53T", Request id "0HMD8Q04CV53T:00000005": An unhandled exception was thrown by the application. System.InvalidOperationException: Headers are read-only, response has already started. at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpHeaders.ThrowHeadersReadOnlyException() at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpResponseHeaders.Microsoft.AspNetCore.Http.IHeaderDictionary.set_ContentType(StringValues value) at Microsoft.AspNetCore.Http.DefaultHttpResponse.set_ContentType(String value) at RioWeb.Infrastructure.MagnusErrorHandler.HandleExceptionAsync(HttpContext context, Exception exception) in D:\_Dev\.net6.rio.next\RioWeb\Infrastructure\MagnusErrorHandler.cs:line 110 at RioWeb.Infrastructure.MagnusErrorHandler.Invoke(HttpContext context) in D:\_Dev\.net6.rio.next\RioWeb\Infrastructure\MagnusErrorHandler.cs:line 64 at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Watch.BrowserRefresh.BrowserRefreshMiddleware.InvokeAsync(HttpContext context) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication1 application)
52 08:14:06.352 Microsoft.AspNetC I: Request finished HTTP/1.1 POST http://localhost:5000/odata/DeviceSummaries text/plain 102 - 200 - application/json;+odata.metadata=minimal;+odata.streaming=true 125.9014ms
`
Same issue here. Updated everything to .NET 6, including EF to 6.0.0 and OData to 8.0.4. $select never returns data now, requests just keep waiting until they receive a timeout. In our case, we aren't using EDM models.
Can see the query being executed inside the logs, but it never gets sent back.
[HttpGet("odata")]
[EnableQuery()]
public IQueryable<ViewModels.WebsiteUsers.WebsiteUser> Get()
{
return authContext.AspNetUsers.Select(x => new ViewModels.WebsiteUsers.WebsiteUser
{
Id = x.Id,
DisplayName = x.DisplayName
});
}
NewtonsoftJson is not supported for .NET6, that is what Microsoft says.
The $select, $expand is a clear oData problem, I don't think that the AddNewtonsoftJson could solve or cause the problem
The problem is when we use: .NET6 Microsoft.AspNetCore.OData 8.0.4 EntityFramework 6.4.4
I just want to let y'all know that we experience the same issue with Version 8.0.4 in this configuration. We do not experience it on version 7.5.12, and have been using that just fine with a Restier-powered OData service on .NET 6.
HTH!
Although this is not a solution (simply an observation for the investigation), removing .AddNewtonsoftJson v6.0.1 from the startup allowed the $select to return a response.
.Net 6, Microsoft.AspNetCore.Mvc.NewtonsoftJson v6.0.1
.AddNewtonsoftJson(opt => { opt.SerializerSettings.ContractResolver = new DefaultContractResolver(); opt.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; })
@rickyzu Thank you for the hint, but I am not using AddNewtonsoftJson at all.
I configure the oData only in ConfigureServices like this. Am I missing something?
// OData services.AddControllers().AddOData(option => { // enable all query features (select, orderby etc) and set the maxTopValue to the given value option.EnableQueryFeatures(1000);
// Set the DateTime Offset to 0 (UTC) so,
// that $filter queries containing ISO date time strings (e.g. "2021-02-11T10:48:59.152Z")
// will not add a date time offset to the query
option.TimeZone = TimeZoneInfo.Utc;
// add EdmModel for the specified routes
option.AddRouteComponents("odata", GetEdmModel());
option.AddRouteComponents("odata/{workspaceId}", GetEdmModel());
});
@athinadev - I noted on the Project site they have a tweaked implementation for developers that use Newtonsoft over system.text.json. If you use Newtonsoft as a library for your JSON then the following sample page will be useful to review.
I was missing the Microsoft.AspNetCore.OData.NewtonsoftJson package and the .AddODataNewtonsoftJson() call after .AddOData(...).
services.AddControllers().AddOData(option =>
{
// enable all query features (select, orderby etc) and set the maxTopValue to the given value
option.EnableQueryFeatures(1000);
// Set the DateTime Offset to 0 (UTC) so,
// that $filter queries containing ISO date time strings (e.g. "2021-02-11T10:48:59.152Z")
// will not add a date time offset to the query
option.TimeZone = TimeZoneInfo.Utc;
// add EdmModel for the specified routes
option.AddRouteComponents("odata", GetEdmModel());
option.AddRouteComponents("odata/{workspaceId}", GetEdmModel());
})
.AddODataNewtonsoftJson();
@rickyzu method resolved the issue for me.
Hi all,
My issue was similar with what was mentioned in this with a few differences: when I was using $select, the app was not returning any response. (the app in NET 6, EF Core 6.x and OData 8.x). The solution in my case was what @rickyzu wrote above (.AddODataNewtonsoftJson() call after .AddOData(...))
Thx @rickyzu.