-
Notifications
You must be signed in to change notification settings - Fork 158
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
Optional Navigations Broken (Nullable object must have a value) #1035
Comments
It's a regression coming from #993 There's a StackOverflow question here. I can reproduce it using the sample provided here You can see User(1) and User(3) have 'null' DataFileRef. With the #993 changes, the LINQ expression has changed from left to right as below: The exception is thrown from the lines in the "black rectangle of the right picture", since "$$it.FileRefNavigation" is null for User(1) and User(3). If I change the LINQ expression as (part): , and It works My suggestion:
|
I've also produced this bug with optional references and have been unable to solve the issue with marking properties as optional in the OData definition. |
@goatrodeosoftware @andy-clymer see my previous comments. |
@xuzhg What would I see about your post? I read it and understand and was hoping to show that I experienced it and couldn't get around it with OData configuration. |
I can build a nightly for you to try it if you are interested. Just let me know. We hope we can fix it as soon as possible and release the official bit. |
@andy-clymer @goatrodeosoftware can you try the nightly Microsoft.AspNetCore.OData 8.9.0-Nightly202308302217 |
@xuzhg I'm sorry, I misunderstood you- I didn't mean that you had to fix something right away to satisfy what I needed, just trying to add info in case it helps. Looks like you've already got it under control. As for me I can just use 8.2.0. I'm happy to try that, but I don't see the package in nuget- does that refer to a branch I'd need to download and reference instead of the nuget package? |
It doesn't matter. If you want to try the nightly (it's not on Nuget.org, but on Myget.Org), see the guides at https://github.com/OData/aspNetCoreOData/#34-nightly-builds . |
@xuzhg Thanks for the quick response and action on this issue. I tried the nightly build that you referenced, and now receive a new error: Argument types do not match. The result still returns okay when this property isn't expanded, however the error arises now whenever I request expansion on that property, even if I only filter to return records that have a value set for the optional navigation. ** Stack Trace** |
I hardcoded the nullable is "int?" So, It seems you have other nullable type? |
That's correct, we use "Guid?" as our foreign key. |
@andy-clymer @goatrodeosoftware would you please try the 8.2.3 and let us know any result? Thanks. |
@xuzhg everything is working correctly now. Thank you. |
@andy-clymer Thanks for your information. Let me close this issue and please file any new issue if you have more questions/concerns. |
in 8.2.5 is broken again System.InvalidOperationException: Nullable object must have a value. |
Assemblies affected
ASP.NET Core OData 8.2.2
.NET 7
EF Core 7.0.10
Describe the bug
When expanding a navigation property that can be nullable, and the result set returns at least one record that doesn't have a value set for this optional navigation (null), the following error is returned: Nullable object must have a value.
This works in version 8.2.0, but is broken in both the version listed above and 8.2.1.
Reproduce steps
Data Model
EDM (CSDL) Model
Request/Response
Request Uri:
Response:
Expected behavior
Expected behavior is to return a response of the queried records that have the optional navigation set if they contain a value and for records that don't have a value set to also be returned. This would make querying work with optional navigations work like it did in version 8.2.0.
Additional context
System.InvalidOperationException: Nullable object must have a value.
at System.Nullable
1.get_Value() at lambda_method18(Closure, QueryContext, DbDataReader, ResultContext, SplitQueryResultCoordinator) at Microsoft.EntityFrameworkCore.Query.Internal.SplitQueryingEnumerable
1.AsyncEnumerator.MoveNextAsync()at System.Text.Json.Serialization.Converters.IAsyncEnumerableOfTConverter
2.OnWriteResume(Utf8JsonWriter writer, TAsyncEnumerable value, JsonSerializerOptions options, WriteStack& state) at System.Text.Json.Serialization.JsonCollectionConverter
2.OnTryWrite(Utf8JsonWriter writer, TCollection value, JsonSerializerOptions options, WriteStack& state)at System.Text.Json.Serialization.JsonConverter
1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state) at System.Text.Json.Serialization.JsonConverter
1.WriteCore(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)at System.Text.Json.Serialization.JsonConverter`1.WriteCoreAsObject(Utf8JsonWriter writer, Object value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.JsonSerializer.WriteCore[TValue](Utf8JsonWriter writer, TValue& value, JsonTypeInfo jsonTypeInfo, WriteStack& state)
at System.Text.Json.JsonSerializer.WriteStreamAsync[TValue](Stream utf8Json, TValue value, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken)
at System.Text.Json.JsonSerializer.WriteStreamAsync[TValue](Stream utf8Json, TValue value, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken)
at System.Text.Json.JsonSerializer.WriteStreamAsync[TValue](Stream utf8Json, TValue value, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonOutputFormatter.WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.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.g__Awaited|28_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
The text was updated successfully, but these errors were encountered: