| 閱文時長 | | 2分鍾 | 字數統計 | | 3212字符 |
| 主要內容 | | 1、引言&背景 2、排查.NetCore啟動失敗詳細過程 3、聲明與參考資料 | ||
| 『記一次.Net Core程序啟動失敗的排查過程』 | |||
| 編寫人 | | SCscHero | 編寫時間 | | 2021/12/23 PM2:6 |
| 文章類型 | | 系列 | 完成度 | | 已完成 |
| 座右銘 | 每一個偉大的事業,都有一個微不足道的開始。 | ||
一、引言&背景 完成度:100%
a) 事件脈絡
昨日在SIT環境做發布,發布后訪問發現變成了503,之后又變成了500.0,而后又變成了500.31。如下異常及圖,於是開始排查。
-
503,Service Unavailable,可能是網站超過了IIS限制。博主判斷不存在此種情況,也不符合特征。於是查找了應用程序池,發現其中的應用被停用了。於是重啟了應用程序池。這時候發現報的錯不一樣了。
-
於是開始排查部署,可能是之前部署的方式不正確,造成.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
- 最終根據.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即可。
