Repository navigation
Closed
Description
If an entity type has a containment EntityType<ProjectTask>().ContainsMany(pt => pt.ProjectTaskAssignments); then action returning an entity collection of this type would fail. It just stop transmitting data to client somewhere on serialization.
Assemblies affected
AspNetCore.OData 7.3.0
AspNET Core 3.1
Reproduce steps
Have entities
public class Project
{
public Guid Id {get;set;}
public virtual ICollection<ProjectTasks> ProjectTasks() {get;set;}
}
public class ProjectTask
{
public Guid Id {get;set;}
public Guid ProjectId {get;set;}
public virtual ICollection<ProjectTaskAssignment> ProjectTaskAssignments {get;set;}
}
public class ProjectTaskAssignment
{
public Guid Id {get;set;}
public Guid ProjectTaskId{get;set;}
}Some ODataController with action
public class ProjectsController : ODataController<Project>
{
public async Task<IActionResult> UpdateProjectTasks([FromODataUri] Guid key,
[FromBody] ODataActionParameters parameters)
{
var projectTasks = ((IEnumerable<ProjectTask>)parameters["projectTasks"]).ToList();
var updatedProjectTasks = await _someService.UpdateProjectTasksAsync(key, projectTasks);
return Ok(updatedProjectTasks);
}
}config smth like
var projectsConfig = builder.EntityType<Project>();
var taskUpdateAction = projectsConfig.Action(nameof(ProjectsController.UpdateProjectTasks));
taskUpdateAction.CollectionEntityParameter<ProjectTask>("projectTasks");
taskUpdateAction.ReturnsCollectionFromEntitySet<ProjectTask>(
"ProjectTasks"));
builder.EntityType<ProjectTask>().ContainsMany(pt => pt.ProjectTaskAssignments);and some repository behind.
Expected result
Calling action returns actual tasks after update.
Actual result
Client logs:
* Received 1031 B chunk
* Received 190 B chunk
* transfer closed with outstanding read data remaining
* Closing connection 20
Server has an unhandled exception (outside of aspnet.core error handling in pipeline) that can be seen in events hub of studio:
Microsoft.OData.ODataException: The Path property in ODataMessageWriterSettings.ODataUri must be set when writing contained elements.
at Microsoft.OData.ODataWriterCore.EnterScope(WriterState newState, ODataItem item)
at Microsoft.OData.ODataWriterCore.WriteStartNestedResourceInfoImplementation(ODataNestedResourceInfo nestedResourceInfo)
at Microsoft.OData.ODataWriterCore.WriteStart(ODataNestedResourceInfo nestedResourceInfo)
at Microsoft.AspNet.OData.Formatter.Serialization.ODataResourceSerializer.WriteNavigationLinks(SelectExpandNode selectExpandNode, ResourceContext resourceContext, ODataWriter writer)
at Microsoft.AspNet.OData.Formatter.Serialization.ODataResourceSerializer.WriteResource(Object graph, ODataWriter writer, ODataSerializerContext writeContext, IEdmTypeReference expectedType)
at Microsoft.AspNet.OData.Formatter.Serialization.ODataResourceSerializer.WriteObjectInline(Object graph, IEdmTypeReference expectedType, ODataWriter writer, ODataSerializerContext writeContext)
at Microsoft.AspNet.OData.Formatter.Serialization.ODataResourceSetSerializer.WriteResourceSet(IEnumerable enumerable, IEdmTypeReference resourceSetType, ODataWriter writer, ODataSerializerContext writeContext)
at Microsoft.AspNet.OData.Formatter.Serialization.ODataResourceSetSerializer.WriteObjectInline(Object graph, IEdmTypeReference expectedType, ODataWriter writer, ODataSerializerContext writeContext)
at Microsoft.AspNet.OData.Formatter.Serialization.ODataResourceSetSerializer.WriteObject(Object graph, Type type, ODataMessageWriter messageWriter, ODataSerializerContext writeContext)
at Microsoft.AspNet.OData.Formatter.ODataOutputFormatterHelper.WriteToStream(Type type, Object value, IEdmModel model, ODataVersion version, Uri baseAddress, MediaTypeHeaderValue contentType, IWebApiUrlHelper internaUrlHelper, IWebApiRequestMessage internalRequest, IWebApiHeaders internalRequestHeaders, Func`2 getODataMessageWrapper, Func`2 getEdmTypeSerializer, Func`2 getODataPayloadSerializer, Func`1 getODataSerializerContext)
at Microsoft.AspNet.OData.Formatter.ODataOutputFormatter.WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeResultAsync>g__Logged|21_0(ResourceInvoker invoker, IActionResult result)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|29_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 where exception was thrown ---
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>g__Awaited|19_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.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
Additional detail
Can supply info and check things if needed, but after I sleep )))
Activity
gathogojr commentedon Feb 18, 2020
@isabekyan Is this only happening with ver. 7.3.0? Was it working with a previous version?
isabekyan commentedon Feb 18, 2020
@gathogojr I don't know.. we are migrating from asp.net classic Microsoft.AspNet.OData 5.9.0 and we did not use containment there.
As a temporary workaround we replace containment config (ContainsMany) to a simple navigation (HasMany) and add own EntitySet for a contained entity. This configuration works OK but this EntitySets are actually redundant.
xuzhg commentedon Feb 18, 2020
I tested this scenario in 7.2.2, it throws the same error message.
In Web API, we had the following setting for "Path"
"IsOperationPath" returns "true" because it's an action call. So, we set the "Path" as null.
But, In the OData Core, it complains about "Path" is equals to "null" for "Containment Navigation property" at https://github.com/OData/odata.net/blob/18abaa5908f8246cb63f45587948d10eb65d1e73/src/Microsoft.OData.Core/ODataWriterCore.cs#L2355-L2362
I'd like get more input for this scenario from @mikepizzo
Fix OData#2056: opertation returns path for the return entity set or …
Fix OData#2056: opertation returns path for the return entity set or …
Fix OData#2056: opertation returns path for the return entity set or …
Fix OData#2056: opertation returns path for the return entity set or …
Fix OData#2056: opertation returns path for the return entity set or …
Fix #2056: opertation returns path for the return entity set or singl…
Fix OData#2056: opertation returns path for the return entity set or …