I have a ASP.NET Web API with OData running on .NET 4.6.1 and in an Azure App Service. During startup, it builds and registers an OData EdmModel for a couple very simple entities. It hangs while building the EdmModel, CPU usage spikes to 100%, becomes unresponsive, and the AppService eventually kills and restarts the process. This is a recent issue.
I've reduced it down to this example:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, IConfiguration configuration)
{
var odataBuilder = new ODataConventionModelBuilder();
odataBuilder.EntitySet<Foo>("Foos");
var edmModel = builder.GetEdmModel(); // hangs here
app.UseMvc(builder => builder.MapODataServiceRoute("odata", "odata", edmModel, new DefaultODataBatchHandler());
}
Where Foo is a simple class with a handful of int, long, string, and DateTimeOffset fields. I've tried it with and without an associated controller at odata/Foos, with the same result either way.
Removing odataBuilder.EntitySet<Foo>("Foos"); avoids the issue, but is obviously not very useful.
Any ideas to further troubleshoot this?
I've also updated the OData packages to the latest 7.x version. I should also note that this is a recent issue, and there haven't been any changes that are obviously related to this code.
Thanks @Marc_s, yes as marc_s said Update the target framework in your project file to a more recent version, such as
net6.0or later.GetEdmModelmethod to build and register the OData EdmModel. Build theEdmModelasynchronously to avoid blocking the main thread. TheGetEdmModelmethod might be causing the hang due to synchronous execution.Program.cs:
OData message:
odataBuilder, but then you attempt to get the EdmModel usingbuilder.GetEdmModel();. This mismatch in variable names is likely causing theNullReferenceException, and the application hangs when trying to build the EdmModel.Code: