[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; });

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">
      <aspNetCore xdt:Transform="SetAttributes(startupTimeLimit)" startupTimeLimit="300">

The run result page is directly inaccessible.



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


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.UseEndpoints(endpoints =>//add


Read More: