Skip to content
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

Issue: Migration from .NET 3.1 to .NET 9.0 – OData Error: "Found more than one dynamic property container #1415

Open
AntoBenil-Official opened this issue Feb 12, 2025 · 3 comments

Comments

@AntoBenil-Official
Copy link

AntoBenil-Official commented Feb 12, 2025

I recently migrated my project from .NET Core 3.1 to .NET 9.0. After the migration, I encountered an OData exception stating:

"Found more than one dynamic property container in type 'HttpRequestMessage'. Each open type must have at most one dynamic property container."

This issue did not occur in .NET Core 3.1 but appeared after moving to .NET 9.0 with AspNetCore.OData 9.1.3.

Here is my OData model builder setup:

var modelBuilder = new ODataConventionModelBuilder
{
    Namespace = "WebAPI",
    ContainerName = "DefaultContainer"
};

// Attempt to exclude HttpRequestMessage
modelBuilder.ComplexType<HttpRequestMessage>().Ignore(hrm => hrm.Properties);

// Function definitions
modelBuilder.Function("GetEntityData")
            .Returns<Task<IActionResult>>()
            .Parameter<string>("EntityName");

modelBuilder.Function("AddEntityData")
            .Returns<Task<IActionResult>>()
            .Parameter<string>("EntityName");

var putEntityData = modelBuilder.Function("UpdateEntityData")
            .Returns<Task<IActionResult>>();

putEntityData.Parameter<string>("EntityName");
putEntityData.Parameter<Guid>("EntityId");

var deleteEntityData = modelBuilder.Function("DeleteEntityData")
            .Returns<Task<IActionResult>>();

deleteEntityData.Parameter<string>("EntityName");
deleteEntityData.Parameter<Guid>("EntityId");

Full Exception Trace:

**System.ArgumentException: Found more than one dynamic property container in type 'HttpRequestMessage'.
Each open type must have at most one dynamic property container. (Parameter 'propertyInfo')
at Microsoft.OData.ModelBuilder.StructuralTypeConfiguration.AddDynamicPropertyDictionary(PropertyInfo propertyInfo)
at Microsoft.OData.ModelBuilder.ODataConventionModelBuilder.MapStructuralType(StructuralTypeConfiguration structuralType)
...
at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.OnActionExecuted(ActionExecutedContext actionExecutedContext)
at Microsoft.AspNetCore.Mvc.Filters.ActionFilterAttribute.OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
...
**

Request for Help

  • Is this a known issue in .NET 9 + OData 9.1.3?
    -Are there new OData model validation rules causing this?
    -What is the correct way to exclude HttpRequestMessage from OData mapping in .NET 9?

Would appreciate any insights or workarounds!

@gathogojr
Copy link
Contributor

gathogojr commented Feb 13, 2025

@AntoBenil-Official Just curious, why would you be adding the framework HttpRequestMessage type to your Edm model?

RE:

modelBuilder.ComplexType<HttpRequestMessage>().Ignore(hrm => hrm.Properties);

How does a framework type that you have no control over become a part of your data model? What is the scenario?

@gathogojr
Copy link
Contributor

@AntoBenil-Official Ping...

@corranrogue9
Copy link
Contributor

I would expect us to consider a type with ambiguous object dictionary properties to be invalid and throw. This seems like we fixed a design issue we previously had.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants