记一次.Net Core程序启动失败的排查过程

阅文时长 | 2分钟 字数统计 | 3212字符
主要内容 | 1、引言&背景 2、排查.NetCore启动失败详细过程 3、声明与参考资料
『记一次.Net Core程序启动失败的排查过程』
编写人 | SCscHero 编写时间 | 2021/12/23 PM2:6
文章类型 | 系列 完成度 | 已完成
座右铭 每一个伟大的事业,都有一个微不足道的开始。

一、引言&背景   完成度:100%

a) 事件脉络

昨日在SIT环境做发布,发布后访问发现变成了503,之后又变成了500.0,而后又变成了500.31。如下异常及图,于是开始排查。

  1. 503,Service Unavailable,可能是网站超过了IIS限制。博主判断不存在此种情况,也不符合特征。于是查找了应用程序池,发现其中的应用被停用了。于是重启了应用程序池。这时候发现报的错不一样了。

  2. 于是开始排查部署,可能是之前部署的方式不正确,造成.NetCore启动有一定问题,于是打开了.NetCore程序的配置。开启启动日志监控。根据启动日志发现了一些信息,进而排查问题。最终解决。如下是.NetCore启动失败的一些返回信息:

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.lIS, was not referenced in the application.
●ANCM could not find dotnet.
Troubleshooting steps:
●Check the system event log for error messages
●Enable logging the application process' stdout messages
●Attach a debugger to the application process and inspect
For more information visit: https://go.microsoft. com/fwlink/?LinklD=2028526
HTTP Error 500.31 - ANCM Failed to Find Native Dependencies
Common solutions to this issue:
The specified version of Microsoft.NetCore.App or Microsoft.AspNetCore.App was not found.
Specific error detected by ANCM:
It was not possible to find any compatible framework version The framework 'Microsoft.AspNetCore.App', version '2.2.0' (x64)was not found. - The following frameworks were found: 2.1.30 at [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] 3.1.18 at [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] 5.0.9 at [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] 6.0.0-rc.1.21452.15 at [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] You can resolve the problem by installing the specified framework and/or SDK. The specified framework can be found at: - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.AspNetCore.App&framework_version=2.2.0&arch=x64&rid=win10-x64
Troubleshooting steps:
Check the system event log for error messages
Enable logging the application process' stdout messages
Attach a debugger to the application process and inspect
For more information visit: https://go.microsoft.com/fwlink/?LinkID=2028526
  1. 最终根据.NetCore启动日志,发现了缺失了.NetCore依赖包JSON文件,如第二章节。

b) 应用场景

  • .NetCore启动报错。

二、排查.NetCore启动失败详细过程   完成度:100%

a) 配置记录启动错误日志

如果是寄托于IIS,则在web.config中加入一段配置。stdoutLogEnabled值设置为true即可。Arguments值设置为应用名称即可。

<aspNetCore processPath="dotnet"
        arguments=".\MyApp.dll"
        stdoutLogEnabled="true"
        stdoutLogFile=".\logs\stdout">
</aspNetCore>

配置完后则在日志路径下可找到日志文件,如图:

b) 详细信息

如图,日志显示缺失了runtimeconfig.json以及deps.json文件。

A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'D:\MCSSolution\XXXXX\publish\'.
Failed to run as a self-contained app. If this should be a framework-dependent app, add the D:\MCSSolution\XXXXX\publish\XXXXX.runtimeconfig.json file specifying the appropriate framework.
Application startup exception: System. IO. FileNotFoundException: Could not find file
'D: \MCSSolution\XXXXX\publish\XXXX.deps.json'.
File name: 'D:'\publish\XXXX. deps. json'
at System. I0. Filestream. ValidateF ileHandle(SafeF ileHandle fileHandle)
at System. I0. FileStream. CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options)
at System. IO. FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System. IO. FileStream.ctor(String path, FileMode mode, FileAccess access, FileShare share)
at System. IO.File .OpenRead(String path)
at Microsoft.Extensions.DependencyModel. Filewrapper.OpenRead(String path)
at Microsoft.Extensions.DependencyModel.DependencyContextLoader.LoadContext(IDependencyContextReader reader, string location)
at Microsoft.Extensions.DependencyModel.DependencyContextLoader.Load(Assembly assembly)
at Microsoft.Extens ions.DependencyModel.DependencyContext.Load(Assembly assembly)
at Microsoft.AspNetCore.MvC.ApplicationParts .Applicat ionAssembliesProvider.LoadDependencyContext(Assembly assembly)
at Microsoft.AspNetCore. MvC .ApplicationParts.ApplicationAssembliesProvider.ResolveAssemblies
(Assembly entryAssembly)+MoveNext()
at Microsoft.AspNetCore.Mvc.ApplicationParts.Applicat ionPartManager.PopulateDefaultParts
(String entryAssemblyName)
at Microsoft.Extens ions.DependencyInjection.MvcCoreServiceCollectionExtens ions.GetApplicationPa
rtManager(IServiceCollection services)

三、声明与参考资料   完成度:100%

原创博文,未经许可请勿转载。

如有帮助,欢迎点赞、收藏、关注。如有问题,请评论留言!如需与博主联系的,直接博客私信SCscHero即可。

posted on 2022-01-18 20:11  SCscHero  阅读(2023)  评论(0编辑  收藏  举报

导航