0

Trying to run an .NET Core web api application in the browser but keep getting the following error:

HTTP Error 500.0 - ANCM In-Process Handler Load Failure

I'm using .NET Framework 5

VS 2019 Community Version 16.11.8

The following .NET Core components have been installed:

  • ASP.NET Core Runtime 5.0.13
  • ASP.NET Core Hosting Bundle
  • .NET Desktop Runtime 5.0.13

AspNetCoreModuleV2 is installed and present under:

Program.cs

public class Program
{
    public static void Main(string[] args)
    {
        CreateWebHostBuilder(args).Build().Run();
    }

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
        .CaptureStartupErrors(true)
        .UseStartup<Startup>();
}

Startup.cs

public class Startup
{
    private const string _dev = "Development";

    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.AddControllers(options => options.EnableEndpointRouting = false);
        services.AddSwaggerGen();
        services.AddRepositories(Configuration);
        services.AddServices(Configuration);
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.EnvironmentName == _dev)
        {
            app.UseDeveloperExceptionPage();
            app.UseSwagger();
            app.UseSwaggerUI();
            app.UseSwaggerUI(options =>
            {
                options.SwaggerEndpoint("/swagger/v1/swagger.json", "v1");
                options.RoutePrefix = string.Empty;
            });
        }
        else
        {
            app.UseHsts();
        }

        app.UseHttpsRedirection();
        app.UseRouting();
        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
        });
    }
}

C:\Program Files\IIS\Asp.Net Core Module\V2\aspnetcorev2.dll

Here is the output of the detailed error logs:

[aspnetcorev2.dll] Current process bitness type detected as isX64=1
[aspnetcorev2.dll] Processing entry 'C:\Program Files\dotnet\dotnet.exe'
[aspnetcorev2.dll] Binary type 6
[aspnetcorev2.dll] Found dotnet.exe via where.exe invocation at 'C:\Program Files\dotnet\dotnet.exe'
[aspnetcorev2.dll] Resolving absolute path to hostfxr.dll from 'C:\Program Files\dotnet\dotnet.exe'
[aspnetcorev2.dll] hostfxr.dll located at 'C:\Program Files\dotnet\host\fxr\5.0.13\hostfxr.dll'
[aspnetcorev2.dll] Parsed hostfxr options: dotnet location: 'C:\Program Files\dotnet\dotnet.exe' hostfxr path: 'C:\Program Files\dotnet\host\fxr\5.0.13\hostfxr.dll' arguments:
[aspnetcorev2.dll] Argument[0] = 'C:\Program Files\dotnet\dotnet.exe'
[aspnetcorev2.dll] Argument[1] = '.\OA.Api.dll'
[aspnetcorev2.dll] c:\b\w\e37dd45d8cd1eaf4\modules\iisintegration\src\aspnetcoremodulev2\commonlib\fileoutputmanager.cpp:142 Operation failed with LastError: 32 HR: 0x80070020
[aspnetcorev2.dll] Event Log: 'Invoking hostfxr to find the inprocess request handler failed without finding any native dependencies. This most likely means the app is misconfigured, please check the versions of Microsoft.NetCore.App and Microsoft.AspNetCore.App that are targeted by the application and are installed on the machine.' 
End Event Log Message.
[aspnetcorev2.dll] Failed HRESULT returned: 0x8000ffff at c:\b\w\e37dd45d8cd1eaf4\modules\iisintegration\src\aspnetcoremodulev2\aspnetcore\handlerresolver.cpp:80 
[aspnetcorev2.dll] Event Log: 'Could not find inprocess request handler. Captured output from invoking hostfxr: ' 
End Event Log Message.
[aspnetcorev2.dll] Failed HRESULT returned: 0x8000ffff at c:\b\w\e37dd45d8cd1eaf4\modules\iisintegration\src\aspnetcoremodulev2\aspnetcore\handlerresolver.cpp:153 
[aspnetcorev2.dll] Failed HRESULT returned: 0x8000ffff at c:\b\w\e37dd45d8cd1eaf4\modules\iisintegration\src\aspnetcoremodulev2\aspnetcore\applicationinfo.cpp:136 
[aspnetcorev2.dll] Failed HRESULT returned: 0x8000ffff at c:\b\w\e37dd45d8cd1eaf4\modules\iisintegration\src\aspnetcoremodulev2\aspnetcore\applicationinfo.cpp:91 
[aspnetcorev2.dll] Event Log: 'Failed to start application '/LM/W3SVC/4/ROOT', ErrorCode '0x8000ffff'.' 
End Event Log Message.

I've been trying for days to google the detailed error but no luck so far on getting a resolution Would appreciate any helpful suggestions

Edit:

I've just discovered something interesting. If I navigate to my bin folder and open up command prompt I can start the application using the dotnet ApplicationName.dll command it displays the URL in the command prompt.I am then able to navigate to the url in the browser and call my api actions.

Still no idea why it's not working in Visual Studio though.

Denys Wessels
  • 16,829
  • 14
  • 80
  • 120
  • https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/azure-iis-errors-reference?view=aspnetcore-6.0#missing-site-extension-32-bit-x86-and-64-bit-x64-site-extensions-installed-or-wrong-process-bitness-set – Richard Deeming Jan 10 '22 at 16:00
  • Could you please tell me your application's version? According to the error message, it seems that your application use some dll which is not match current version. You need to install the right .net core runtime which match your project develop version. – Brando Zhang Jan 11 '22 at 05:28
  • @BrandoZhang my application is .NET 5 and I have .NET core runtime and hosting bundle installed for version 5 – Denys Wessels Jan 11 '22 at 20:07
  • Maybe include your Program.cs/Startup.cs code? – T. van Schagen Jan 11 '22 at 21:10
  • @T.vanSchagen added the files as requested.Please see if you can spot something odd – Denys Wessels Jan 11 '22 at 21:22

3 Answers3

1

For some reason I had to add a web.config file to my project in Visual Studio and then it runs in IISExpress. Here is the web.config file in case someone might have the same problem. Just replace the processPath with the location of your .exe

<?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="bin\Debug\net5.0\OA.Api.exe" arguments="" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="InProcess">
        <handlerSettings>
          <handlerSetting name="debugFile" value=".\logs\aspnetcore-debug.log" />
          <handlerSetting name="debugLevel" value="FILE,TRACE" />
        </handlerSettings>
      </aspNetCore>
    </system.webServer>
  </location>
</configuration>
Denys Wessels
  • 16,829
  • 14
  • 80
  • 120
0

You just have to set your process from InProcess to OutOfProcess from properties.

try this for your reference.

Kiran Joshi
  • 1,758
  • 2
  • 11
  • 34
0

As you mention you are able to start up your application outside of IIS, it looks like a configuration error related to IIS (a 500.0 error could in theory be anything). I assume you are trying to use a local IIS installation to run your app (not IIS Express). Have you tried adding UseIIS() in creating your hostbuilder?