[Solved] .NetCore2.2 Upgrade to 3.1 Error: HTTP Error 500.37 – ANCM Failed to Start Within Startup Time

During the upgrade of an old project from netcore2.2 to 3.1, an Ocelot gateway interface program changes the project file

- <TargetFramework>netcoreapp2.2</TargetFramework> 
+ <TargetFramework>netcoreapp3.1</TargetFramework>

Replace the Services.Addmvc() in your project:

services.AddMvc(options => { options.EnableEndpointRouting = false; });
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);

The method Configure(IApplicationBuilder app, IWebHostEnvironment env) retains the original app.UseMvc();
The compiler passed, but the runtime page reported an error: HTTP Error 500.37 – ANCM Failed to Start Within Startup Time, searched the web for a solution and gave a way to modify the startupTimeLimit value.

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <location>
    <system.webServer>
      <aspNetCore xdt:Transform="SetAttributes(startupTimeLimit)" startupTimeLimit="300">
      </aspNetCore>
    </system.webServer>
  </location>
</configuration>

The run result page is directly inaccessible.

 

Solution:

You only need to add a project node
< AspNetCoreHostingModel> OutOfProcess OK.

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
	<AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
  </PropertyGroup>

After doing the above, the project runs normally. In addition, the above services.AddMvc() is not the recommended solution.

AddMvc(); comment out app.UseMvc() in the Configure method; then add the following code.

            //app.UseMvc();
            app.UseRouting();//add
            app.UseEndpoints(endpoints =>//add
            {
                endpoints.MapControllers();
            });

 

Read More: