.NET 8 Isolated本地Azure函数报错:超出语言工作进程重启重试次数
.NET 8 Isolated模式Azure Functions本地启动失败(错误码0x80008096)
问题详情
正在将Azure Functions项目从.NET 6升级至.NET 8 Isolated模式,本地运行时触发异常。新建的.NET 8 Isolated测试项目和已部署到生产环境的原有项目,本地运行均出现相同错误。
错误日志如下:
C:\Program Files\dotnet\dotnet.exe WorkingDirectory:C:\Users\LCK3SNS\source\repos\gcs-gcs-app\Hive.Azure.Functions\bin\Debug\net8.0 Arguments: "C:\Users\LCK3SNS\source\repos\gcs-gcs-app\Hive.Azure.Functions\bin\Debug\net8.0\Hive.Azure.Functions.dll" --host 127.0.0.1 --port 50616 --workerId acfc8109-5970-40a0-9703-c1ccd5d49630 --requestId 67f55fc8-9726-4c85-9322-fb7670094c46 --grpcMaxMessageLength 2147483647 --functions-uri http://127.0.0.1:50616/ --functions-worker-id acfc8109-5970-40a0-9703-c1ccd5d49630 --functions-request-id 67f55fc8-9726-4c85-9322-fb7670094c46 --functions-grpc-max-message-length 2147483647 [2024-07-14T01:53:56.732Z] C:\Program Files\dotnet\dotnet.exe process with Id=29220 started [2024-07-14T01:53:56.973Z] Process 29220 has exited with code -2147450730. [2024-07-14T01:53:56.980Z] Language Worker Process exited. Pid=29220. [2024-07-14T01:53:56.983Z] C:\Program Files\dotnet\dotnet.exe exited with code -2147450730 (0x80008096). https://aka.ms/dotnet/app-launch-failed. [2024-07-14T01:53:56.991Z] Handling WorkerErrorEvent for runtime:dotnet-isolated, workerId:dotnet-isolated. Failed with: Microsoft.Azure.WebJobs.Script.Workers.WorkerProcessExitException: C:\Program Files\dotnet\dotnet.exe exited with code -2147450730 (0x80008096) [2024-07-14T01:53:56.995Z] ---> System.Exception: https://aka.ms/dotnet/app-launch-failed [2024-07-14T01:53:56.997Z] --- End of inner exception stack trace --- [2024-07-14T01:53:57.003Z] Attempting to dispose webhost or jobhost channel for workerId: 'acfc8109-5970-40a0-9703-c1ccd5d49630', runtime: 'dotnet-isolated' [2024-07-14T01:53:57.020Z] No initialized worker channels for runtime 'dotnet-isolated'. Delaying future invocations [2024-07-14T01:53:57.024Z] Restarting worker channel for runtime: 'dotnet-isolated' [2024-07-14T01:53:57.030Z] Exceeded language worker restart retry count for runtime:dotnet-isolated. Shutting down and proactively recycling the Functions Host to recover
已尝试的操作:
- 卸载重装Azure Functions Core Tools
- 清理Visual Studio缓存
- 重建项目
- 重启电脑
怀疑问题源于本地未关闭的连接或进程耗尽(本地有PostgreSQL数据库连接)。
解决方案
1. 验证.NET 8与Functions Core Tools兼容性
确保本地安装最新稳定版的Azure Functions Core Tools v4.x和完整的.NET 8 SDK(含运行时)。执行以下命令确认版本:
dotnet --version func --version
2. 清理占用进程与端口
- 打开任务管理器,结束所有
dotnet.exe和func.exe进程,再重新启动项目 - 检查日志中指定的端口(示例中为50616)是否被占用,可修改
local.settings.json中的FUNCTIONS_CUSTOMHANDLER_PORT字段,指定一个未被使用的端口
3. 修复.NET运行时损坏
错误码0x80008096常与.NET运行时损坏相关,执行以下命令修复:
dotnet repair
4. 检查项目配置正确性
项目文件(.csproj)配置
确认已正确设置目标框架和Isolated模式依赖:
<PropertyGroup> <TargetFramework>net8.0</TargetFramework> <AzureFunctionsVersion>v4</AzureFunctionsVersion> <OutputType>Exe</OutputType> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.20.0" /> <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.0" /> </ItemGroup>
local.settings.json配置
确保运行时设置为dotnet-isolated:
{ "IsEncrypted": false, "Values": { "AzureWebJobsStorage": "UseDevelopmentStorage=true", "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated" } }
5. 排查数据库连接影响
暂时注释掉项目中所有PostgreSQL连接相关代码,启动项目验证是否是数据库连接导致的启动失败:
- 如果启动正常,逐步检查连接字符串是否正确
- 确认Npgsql等数据库客户端包已升级至支持.NET 8的版本
6. 启用详细日志定位问题
修改host.json添加详细日志配置,获取更具体的启动错误信息:
{ "logging": { "logLevel": { "Microsoft.Azure.Functions.Worker": "Debug", "System.Net.Http": "Debug", "Microsoft.Extensions.Hosting": "Debug" } } }
内容的提问来源于stack exchange,提问作者Ronak Panchal
相关产品推荐
相关产品推荐

