Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Core fails to run under IIS: HTTP Error 500.0 - ANCM In-Process Handler Load Failure

I just upgraded my web application from ASP.NET (Framework) MVC to ASP.NET Core 2.2. The application runs fine under IIS Express, however as soon as I try to run it under IIS it gives the generic error:

HTTP Error 500.0 - ANCM In-Process Handler Load Failure Common causes of this issue: The specified version of Microsoft.NetCore.App or Microsoft.AspNetCore.App was not found. The in process request handler, Microsoft.AspNetCore.Server.IIS, was not referenced in the application. ANCM could not find dotnet.

I've searched the web and see that many developers are running into the same issue, it seems that Microsoft really missed the mark on this one and have made it as painful as possible to develop ASP.NET Core apps under IIS. Regardless, I'd like to break through this brick wall that I've been hitting my head against for the last 24 hours, so could use some help.

Things I've tried so far:

  • Installed the latest version of .NET Core Runtime and Hosting Bundle, version 2.2.4.

  • Installed the latest version of .NET Core SDK, version 2.2.203.

  • Ensured that "dotnet" is runnable from command line, and that the x64 version is before the x86 version in my environment variables.

C:\WINDOWS\system32>where dotnet C:\Program Files\dotnet\dotnet.exe C:\Program Files (x86)\dotnet\dotnet.exe

  • Tried changing my auto-generated Web.config from aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" to aspNetCore processPath="dotnet" arguments="./Housters.Web.dll" however the changes don't stick, every time I build my web application the Web.config gets reverted back tot he original %LAUNCHER_PATH% values.

  • Tried changing "AspNetCoreModuleV2" to "AspNetCoreModule" in the Web.config.

  • Added IsTransformWebConfigDisabled=true to my Web.csproj file in order to keep my custom Web.config from being overwritten. It didn't work, the Web.config is still overwritten.

  • Tried switching AspNetCoreHostingModel=InProcess to RuntimeFrameworkName=Microsoft.AspNetCore.App in my Web.csproj file.

  • Cleaning the solution, as well as manually deleting the bin, obj, and even .vs folders.

None of these methods helped, I still get the same ANCM In-Process Handler Load Failure error. The Event Viewer does show a more useful error:

Application 'C:\Housters\Web\' wasn't able to start. Executable was not found at 'C:\Housters\Web\%LAUNCHER_PATH%.exe'

However, I can't do anything about that because my Web.config changes don't persist. But really, the default settings should work out of the box, we shouldn't have to jump through hoops to get IIS development working. Why is it looking for an .exe when an ASP.NET Core project by default only generates a .dll? And why isn't it replacing %LAUNCHER_PATH% with the correct path, e.g. "bin/Debug"?

EDIT: I should also mention that at times I've been able to get my custom Web.config to persist, and when I do then every time I try to run the web application I get a JIT debugger prompt:

enter image description here

Choosing to debug, or viewing the event log just gives me a really unfriendly error message:

Faulting application name: w3wp.exe, version: 10.0.17134.1, time stamp: 0xed729d4e Faulting module name: KERNELBASE.dll, version: 10.0.17134.556, time stamp: 0xb9f4a0f1 Exception code: 0xc0020001 Fault offset: 0x000000000003a388 Faulting process id: 0x2650 Faulting application start time: 0x01d502b1f21b112e Faulting application path: c:\windows\system32\inetsrv\w3wp.exe Faulting module path: C:\WINDOWS\System32\KERNELBASE.dll Report Id: 5b5c14cb-8ffa-47b4-8cc1-42f951bc1256 Faulting package full name: Faulting package-relative application ID:

like image 661
Justin Avatar asked May 04 '19 19:05

Justin


Video Answer


1 Answers

You're getting this error because you're not specifying if you want the website hosted in process or out of process... in process can be specified by using UseIIS().

Try changing your CreateWebHostBuilder method in Program.cs to:

public static IWebHostBuilder CreateWebHostBuilder(string[] args) 
{
    var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
    var builder = WebHost.CreateDefaultBuilder(args);

    if (env == EnvironmentName.Staging || env == EnvironmentName.Production)
        builder.UseIIS();

    builder.UseStartup<Startup>();
    return builder;
}

I set ASPNETCORE_ENVIRONMENT in my .pubxml deployment profile by adding:

  <PropertyGroup>
    <EnvironmentName>Staging</EnvironmentName>
  </PropertyGroup>
like image 54
Liam Avatar answered Oct 02 '22 02:10

Liam