.NET Core HTTP 错误 500.0 - ANCM 进程内处理程序加载失败
.NET Core HTTP Error 500.0 - ANCM In-Process Handler Load Failure
尝试在浏览器中 运行 .NET Core web api 应用程序,但不断收到以下错误:
HTTP 错误 500.0 - ANCM 进程内处理程序加载失败
我正在使用 .NET Framework 5
VS 2019 社区版本 16.11.8
已安装以下 .NET Core 组件:
- ASP.NET 核心运行时 5.0.13
- ASP.NET 核心托管捆绑包
- .NET 桌面运行时 5.0.13
AspNetCoreModuleV2 安装并存在于:
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
这里是详细错误日志的输出:
[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.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.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.
我已经尝试了几天 google 详细的错误,但到目前为止还没有找到解决方案
非常感谢任何有用的建议
编辑:
我刚刚发现了一些有趣的东西。如果我导航到我的 bin 文件夹并打开命令提示符,我可以使用 dotnet ApplicationName.dll
命令启动应用程序,它在命令 prompt.I 中显示 URL 然后能够导航到 url 在浏览器中调用我的 api 操作。
仍然不知道为什么它在 Visual Studio 中不起作用。
您只需在属性中将进程设置为 InProcess
到 OutOfProcess
。
尝试供您参考。
正如您提到的,您可以在 IIS 之外启动您的应用程序,这看起来像是与 IIS 相关的配置错误(理论上 500.0 错误可能是任何错误)。我假设您正在尝试使用本地 IIS 安装来 运行 您的应用程序(不是 IIS Express)。您是否尝试过在创建主机构建器时添加 UseIIS()
?
出于某种原因,我不得不将 web.config 文件添加到我在 Visual Studio 中的项目,然后它在 IISExpress 中运行。这是 web.config 文件,以防有人遇到同样的问题。只需将 processPath
替换为您的 .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>
尝试在浏览器中 运行 .NET Core web api 应用程序,但不断收到以下错误:
HTTP 错误 500.0 - ANCM 进程内处理程序加载失败
我正在使用 .NET Framework 5
VS 2019 社区版本 16.11.8
已安装以下 .NET Core 组件:
- ASP.NET 核心运行时 5.0.13
- ASP.NET 核心托管捆绑包
- .NET 桌面运行时 5.0.13
AspNetCoreModuleV2 安装并存在于:
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
这里是详细错误日志的输出:
[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.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.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.
我已经尝试了几天 google 详细的错误,但到目前为止还没有找到解决方案 非常感谢任何有用的建议
编辑:
我刚刚发现了一些有趣的东西。如果我导航到我的 bin 文件夹并打开命令提示符,我可以使用 dotnet ApplicationName.dll
命令启动应用程序,它在命令 prompt.I 中显示 URL 然后能够导航到 url 在浏览器中调用我的 api 操作。
仍然不知道为什么它在 Visual Studio 中不起作用。
您只需在属性中将进程设置为 InProcess
到 OutOfProcess
。
尝试
正如您提到的,您可以在 IIS 之外启动您的应用程序,这看起来像是与 IIS 相关的配置错误(理论上 500.0 错误可能是任何错误)。我假设您正在尝试使用本地 IIS 安装来 运行 您的应用程序(不是 IIS Express)。您是否尝试过在创建主机构建器时添加 UseIIS()
?
出于某种原因,我不得不将 web.config 文件添加到我在 Visual Studio 中的项目,然后它在 IISExpress 中运行。这是 web.config 文件,以防有人遇到同样的问题。只需将 processPath
替换为您的 .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>