.NET Core 8.0部署IIS启动失败:运行时封送系统禁用引发错误
IIS部署ASP.NET Core 8.0 Web API启动异常解决
问题详情
在IIS上启动ASP.NET Core 8.0 Web API时触发以下异常:
AgentStatus=Failed (Initializing), AD=Shared Domain
Failed to initialize agent: Cannot marshal 'parameter #1':
Cannot marshal managed types when the runtime marshalling system is disabled.at Microsoft.AspNetCore.Builder.WebApplication.get_Environment()
at Program.$(String[] args) in Program.cs:line 16
附相关配置截图:
- 应用程序池配置截图
- Web.config配置截图
- .NET Core版本信息截图
解决步骤
1. 排查Native AOT配置
如果项目启用了Native AOT发布,该特性可能导致与IIS托管模块的兼容性问题:
- 打开项目文件(
.csproj),移除或注释Native AOT相关配置:<!-- <PublishAot>true</PublishAot> --> - 若必须使用Native AOT,请严格遵循官方IIS部署指南,确保模块版本和部署流程匹配。
2. 恢复运行时封送功能
异常提示明确指向运行时封送系统被禁用,需检查以下配置:
- runtimeconfig.json:确认文件中不存在禁用封送的配置,若有则修改为
true或移除:{ "runtimeOptions": { "configProperties": { // 移除或修改此项 // "System.Runtime.EnableRuntimeMarshalling": false } } } - 项目文件(.csproj):检查是否存在禁用封送的设置,移除或注释:
<!-- <EnableRuntimeMarshalling>false</EnableRuntimeMarshalling> -->
3. 匹配ASP.NET Core托管模块版本
确保服务器上安装的ASP.NET Core Hosting Bundle版本与项目使用的.NET 8.0完全一致,建议下载最新稳定版重新安装。
4. 检查应用程序池配置
- 确认应用程序池的
.NET CLR版本设置为无托管代码(ASP.NET Core无需IIS托管CLR)。 - 验证应用程序池标识对网站目录及资源有读写权限。
5. 修正Web.config配置
确保Web.config中的ASP.NET Core模块配置正确,示例如下:
<?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="dotnet" arguments=".\YourApi.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" /> </system.webServer> </location> </configuration>
若使用outofprocess托管模式,需确保模块版本支持且配置无误。
内容的提问来源于stack exchange,提问作者amoncada
相关产品推荐
相关产品推荐

