4
votes

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.

3
There's likely an exception being thrown during startup. Just because it runs locally doesn't mean it's going to run when published. There's always dependencies like database connections and such that will vary and could lead to exceptions. Try opening a command prompt to your publish app directory on the production server and running dotnet MyApp.dll. Do you see any exceptions? If so, add those to your question along with the stack trace.Chris Pratt
I forgot mention that I did that and it loads and runs. I also forgot to mention that stdout file is created but no contents.tonyatl
and dependenies are minimal to none - ie no db, this is the default boiler plate code out of vs template. it was a starter/learner project with 0 added codetonyatl
The AspNetCoreModuleV2 indicates running "in-process". Do you run more than one site per app pool ? ... Asking as the default in-process setup can only have one site per app pool.Ason
the apppool serves only 1 app and is set to unmanaged and runs under apppool identitytonyatl

3 Answers

11
votes

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.

3
votes

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.

2
votes

We have the exact same issue and removing the environment variable worked for us.

The reason was we had the same environment variables set up in both IIS and in file web.config.

My guest is builder.AddEnvironmentVariable() throws duplicate key exception when building the IConfiguration.

To check your IIS environment variable, go to your site, ConfigurationEditor-> select system.webServer/aspNetCore at the top Section.