Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Core 2.2 - "HTTP Error 500.30 - ANCM In-Process Start Failure"

When hosting an ASP.NET Core MVC application on Windows Server 2016 data center running IIS 10, the application fails to load with the message:

HTTP Error 500.30 - ANCM In-Process Start Failure

I created the application with Visual Studio 2017 (9) using .NET Core 2.2 although I installed .NET Core 2.2.3 on the server.

On the server:

dotnet --info
.NET Core SDK (reflecting any global.json):

 Version:   2.2.105
 Commit:    7cecb35b92

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.14393
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.2.105\

Host (useful for support):
  Version: 2.2.3
  Commit:  6b8ad509b6

.NET Core SDKs installed:
  2.1.4 [C:\Program Files\dotnet\sdk]
  2.2.105 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

Windows Application Event Log shows:

Application '/LM/W3SVC/3/ROOT' with physical root 'C:\inetpub\wwwroot\healthmonitormvc' failed to load clr and managed application. Unexpected exception: HRESULT 0x800700b7 returned at c:\b\w\da744fbcc13abce\src\servers\iis\aspnetcoremodulev2\inprocessrequesthandler\inprocessapplication.cpp:198

There are a couple of threads on GitHub concerning this error and hresult, but no resolutions.

The same code works on a local IIS. myapp.exe also loads (as does dotnet myapp.dll), so it seems to be an IIS configuration issue (or .NET Core defect as indicated on GitHub which implies that I may be seeking a work-around). A stdout file is created, but it doesn't have any contents.

This project is part of a solution with non-core projects. However, I published the project using Visual Studio web publisher and it runs as expected.

One Stack Overflow question recommended changing to OutOfProcess as the hosting model, but I do not want to use out of process. It also fails to load with the same hresult. It may be the case that .NET 2.2.3 is broken in a major way. But since I can run it locally, there exists a configuration which works.

This is the web.config file for the application:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath=".\my.name.space.HealthMonitor.Mvc.exe" arguments="exec &quot;.\my.anme.space.HealthMonitor.Mvc.dll&quot;" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="InProcess">
        <environmentVariables>
          <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
        </environmentVariables>
      </aspNetCore>
      </system.webServer>
  </location>
    <system.web>
        <compilation targetFramework="netcoreapp2.2" />
    </system.web>
</configuration>

I expect the page to load as it does in IIS Express or IIS local in which the default out-of-the-box page is displayed.

like image 830
tonyatl Avatar asked Dec 03 '22 10:12

tonyatl


2 Answers

I had the same issue, and I found that running dotnet YourAPI.dll in Azure App Service. Go to:

App ServiceAdvanced ToolsGo (it will take you to Kudu) → Debug consolePowerShell;

Then navigate to site/wwwroot and now run:

dotnet YourAPI.dll

The result showed me a detailed error message.

like image 112
Garran Avatar answered Dec 09 '22 14:12

Garran


Removing the environment variable

<environmentVariables>
  <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="DEVELOPMENT" />
</environmentVariables>

causes the page to load. I do not fully understand why. Clearly I do not understand how it interacts with the application (although I thought I did).

server set shows:

> ASPNETCORE_ENVIRONMENT=Development

I did notice that the IIS Manager configuration editor showed DEVELOPMENT along with my Development for the same environment variable.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace My.Name.Space.HealthMonitor.Mvc
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure<CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.Configure<IISServerOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.AutomaticAuthentication = true;
            });

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
    }
}

The problem is essentially solved and shows me that I need to understand ASPNETCORE_ENVIRONMENT better.

like image 36
tonyatl Avatar answered Dec 09 '22 13:12

tonyatl