顯示具有 Debugger 標籤的文章。 顯示所有文章
顯示具有 Debugger 標籤的文章。 顯示所有文章

2025年4月17日 星期四

[研究]Visual Studio Just-In-Time Debugger (Visual Studio 即時偵錯工具)

[研究]Visual Studio Just-In-Time Debugger (Visual Studio 即時偵錯工具)

2025-04-17

環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C# + SQL Server 2019 + SQL Server Management Studio (SSMS) 19

********************************************************************************


Visual Studio Just-In-Time Debugger

An unhandled Microsoft.NET Frarnework exception occurred in [9064]
w3wp.exe. Just-In-Time debugging this exception failed with the
following error: No installed debugger has Just-In-Time debugging
enabled. In Visual Studio, Just-In-Time debugging can be enabled from
Tools/Options/Debugging/Just-In-Time.

Check the documentation index for 'Just-in-time debugging, errors' for
more information.

Visual Studio 即時偵錯工具

[9064] w3wp.exe 中發生未處理的 Microsoft.NET Frarnework 例外。對此異常進行即時偵錯失敗,並出現以下錯誤:沒有安裝啟用即時偵錯的偵錯器。在 Visual Studio 中,可以從工具/選項/偵錯/Just-In-Time 啟用即時偵錯。

請查看文件索引中的「即時偵錯,錯誤」以取得更多資訊。

********************************************************************************

ChatGPT 說:

這個訊息是來自 Visual Studio Just-In-Time Debugger,它表示在執行 w3wp.exe(IIS 的應用程式工作處理程序)時發生了 未處理的 .NET 例外(Unhandled Exception),而系統試圖使用 Visual Studio 來進行 Just-In-Time(JIT)偵錯,但失敗了。以下是詳細說明:

An unhandled Microsoft.NET Framework exception occurred in [9064] w3wp.exe.   

代表意思:某個 .NET Web 應用程式在 IIS 的工作處理程序中發生了未處理的例外(Crash)。

[9064] 是發生問題的處理程序 ID(Process ID)。

Just-In-Time debugging this exception failed with the following error:   
No installed debugger has Just-In-Time debugging enabled.

代表意思:系統想要用 Visual Studio 來即時偵錯這個錯誤,但找不到一個啟用了 JIT 的偵錯器。

In Visual Studio, Just-In-Time debugging can be enabled from   
Tools/Options/Debugging/Just-In-Time.

建議:你可以在 Visual Studio 裡開啟 JIT 偵錯功能(方法見下方)。

💥 發生原因

  • 應用程式有錯誤(如 NullReferenceException、AccessViolationException 等),但這個例外未被 try-catch 處理。
  • 系統預設想要呼叫 Visual Studio 的 Just-In-Time Debugger 來幫你開啟這個錯誤的位置,但:
    • Visual Studio 沒安裝好
    • 或你沒啟用 JIT Debugging
    • 或使用者帳戶無法啟動 Visual Studio(例如 w3wp 執行帳戶是 IIS AppPool 身份)

🛠️ 處理方法

✅ 一般建議做法(推薦)

  1. 避免未處理例外:在程式中加入 try-catch 處理並適當記錄錯誤(例如用 log 檔記錄)。
  2. 查看應用程式事件記錄(Event Viewer):
    • 打開「事件檢視器」
    • 查看 Windows Logs → Application
    • 找到 w3wp.exe 錯誤記錄,可以看到例外的詳細資訊
  3. 使用 Logging 套件:
    • 如:log4net、Serilog、NLog 等,記錄錯誤資訊方便追蹤問題。

🔧 若你是開發者想用 Visual Studio Debug:

  1. 開啟 Visual Studio。
  2. 點選 工具 (Tools) → 選項 (Options) → 偵錯 (Debugging) → Just-In-Time。
  3. 勾選你需要的項目,例如:
    • Managed
    • Native
    • Script

⚠️ 注意:

  • JIT Debugging 只在開發機使用,不建議在生產環境啟用。
  • 如果是在 Server(非 Visual Studio 環境)看到這個錯誤,代表應該改為寫入 log 而不是試圖啟動 Visual Studio。

🧯 關閉 JIT Debugging 錯誤提示(如你不想看到)

如果你不希望看到這個 JIT Debugging 視窗,可以:

修改登錄檔(註冊表):

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework
DWORD: DbgJITDebugLaunchSetting
Value: 2

  • 0:使用預設行為(顯示 JIT)
  • 1:啟動 JIT Debugger
  • 2:不要啟動 JIT Debugger(建議生產環境設定)

(完)

相關

2022年4月18日 星期一

[研究][ASP.NET]Visual Studio 2022 Just-In-Time Debugger 預設設定

[研究][ASP.NET]Visual Studio 2022 Just-In-Time Debugger 預設設定

2022-04-17



登錄機碼中有關 VsJITDebugger.exe 的設定

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\AppID\VsJITDebugger.exe]
"AppID"="{E62A7A31-6025-408E-87F6-81AEB0DC9347}"

[HKEY_CLASSES_ROOT\CLSID\{36BBB745-0999-4FD8-A538-4D4D84E4BD09}\LocalServer32]
@="\"C:\\Windows\\system32\\vsjitdebugger.exe\""

[HKEY_CLASSES_ROOT\CLSID\{BBE60DE4-551F-444A-81AB-70ADAF417C5D}]
"AppID"="{534E4CF4-3249-4842-8D65-A9BEAE0BBEAC}"
"LocalizedString"="@C:\\Windows\\system32\\vsjitdebugger.exe,-201"
@="CLSID_PrivJITDebuggingHost"

[HKEY_CLASSES_ROOT\CLSID\{BBE60DE4-551F-444A-81AB-70ADAF417C5D}\Elevation]
"Enabled"=dword:00000001

[HKEY_CLASSES_ROOT\CLSID\{BBE60DE4-551F-444A-81AB-70ADAF417C5D}\LocalServer32]
@="\"C:\\Windows\\system32\\vsjitdebugger.exe\" -PrivEmbedding"

[HKEY_CLASSES_ROOT\CLSID\{D40DAF26-8F39-4430-97B9-D3E1A42426C8}\LocalServer32]
"JitExeFilePath"="\"C:\\Windows\\system32\\vsjitdebugger.exe\""

[HKEY_CLASSES_ROOT\WOW6432Node\AppID\VsJITDebugger.exe]
"AppID"="{E62A7A31-6025-408E-87F6-81AEB0DC9347}"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\AppID\VsJITDebugger.exe]
"AppID"="{E62A7A31-6025-408E-87F6-81AEB0DC9347}"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{36BBB745-0999-4FD8-A538-4D4D84E4BD09}\LocalServer32]
@="\"C:\\Windows\\system32\\vsjitdebugger.exe\""

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{BBE60DE4-551F-444A-81AB-70ADAF417C5D}]
"AppID"="{534E4CF4-3249-4842-8D65-A9BEAE0BBEAC}"
"LocalizedString"="@C:\\Windows\\system32\\vsjitdebugger.exe,-201"
@="CLSID_PrivJITDebuggingHost"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{BBE60DE4-551F-444A-81AB-70ADAF417C5D}\Elevation]
"Enabled"=dword:00000001

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{BBE60DE4-551F-444A-81AB-70ADAF417C5D}\LocalServer32]
@="\"C:\\Windows\\system32\\vsjitdebugger.exe\" -PrivEmbedding"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{D40DAF26-8F39-4430-97B9-D3E1A42426C8}\LocalServer32]
"JitExeFilePath"="\"C:\\Windows\\system32\\vsjitdebugger.exe\""

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\WOW6432Node\AppID\VsJITDebugger.exe]
"AppID"="{E62A7A31-6025-408E-87F6-81AEB0DC9347}"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework]
"Enable64Bit"=dword:00000001
"InstallRoot"="C:\\Windows\\Microsoft.NET\\Framework64\\"
"NGenTaskDelayStart"=dword:00000001
"NGenTaskDelayStartAmount"=dword:00000000
"UseRyuJIT"=dword:00000001
"DbgManagedDebugger"="\"C:\\Windows\\system32\\vsjitdebugger.exe\" PID %d APPDOM %d EXTEXT \"%s\" EVTHDL %d"
"DbgJITDebugLaunchSetting"=dword:00000010

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Low Rights\ElevationPolicy\{E62A7A31-6025-408E-87F6-81AEB0DC9347}]
"AppName"="vsjitdebugger.exe"
"AppPath"="C:\\Windows\\system32\\"
"Policy"=dword:00000023

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\91510DF5BDA6E2E4AAA3282A0C1CAB9F]
"00000000000000000000000000000000"="C:\\?Windows\\SysWOW64\\vsjitdebugger.exe"
"80637F3449C5F6341A6E0EA9EC863019"="C:\\?Windows\\SysWOW64\\vsjitdebugger.exe"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\91510DF5BDA6E2E4AAA3282A0C1CAB9F\80637F3449C5F6341A6E0EA9EC863019]
"PatchGUID"=""
"MediaCabinet"=""
"File"="VsJitDebuggerExe32"
"ComponentVersion"="17.0.114.0"
"ProductVersion"="17.0.114"
"PatchSize"="0"
"PatchAttributes"="0"
"PatchSequence"="0"
"SharedComponent"="0"
"IsFullFile"="0"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\91510DF5BDA6E2E4AAA3282A0C1CAB9F]
"00000000000000000000000000000000"="C:\\?Windows\\SysWOW64\\vsjitdebugger.exe"
"80637F3449C5F6341A6E0EA9EC863019"="C:\\?Windows\\SysWOW64\\vsjitdebugger.exe"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\91510DF5BDA6E2E4AAA3282A0C1CAB9F\80637F3449C5F6341A6E0EA9EC863019]
"PatchGUID"=""
"MediaCabinet"=""
"File"="VsJitDebuggerExe32"
"ComponentVersion"="17.0.114.0"
"ProductVersion"="17.0.114"
"PatchSize"="0"
"PatchAttributes"="0"
"PatchSequence"="0"
"SharedComponent"="0"
"IsFullFile"="0"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\A4141D667AB62A941B29D3943D5CC78F]
"00000000000000000000000000000000"="C:\\?Windows\\system32\\vsjitdebugger.exe"
"80637F3449C5F6341A6E0EA9EC863019"="C:\\?Windows\\system32\\vsjitdebugger.exe"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\A4141D667AB62A941B29D3943D5CC78F\80637F3449C5F6341A6E0EA9EC863019]
"PatchGUID"=""
"MediaCabinet"=""
"File"="VsJitDebuggerExe64"
"ComponentVersion"="17.0.114.0"
"ProductVersion"="17.0.114"
"PatchSize"="0"
"PatchAttributes"="0"
"PatchSequence"="0"
"SharedComponent"="0"
"IsFullFile"="0"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\SharedDLLs]
"C:\\Windows\\system32\\vsjitdebugger.exe"=dword:00000002
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug]
"UserDebuggerHotKey"=dword:00000000
"Debugger"="\"C:\\Windows\\system32\\vsjitdebugger.exe\" -p %ld -e %ld -j 0x%p"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug\AutoExclusionList]
"DWM.exe"=dword:00000001

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Classes\AppID\VsJITDebugger.exe]
"AppID"="{E62A7A31-6025-408E-87F6-81AEB0DC9347}"

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\.NETFramework]
"InstallRoot"="C:\\Windows\\Microsoft.NET\\Framework\\"
"NGenTaskDelayStart"=dword:00000001
"NGenTaskDelayStartAmount"=dword:00000000
"DbgManagedDebugger"="\"C:\\Windows\\system32\\vsjitdebugger.exe\" PID %d APPDOM %d EXTEXT \"%s\" EVTHDL %d"
"DbgJITDebugLaunchSetting"=dword:00000010

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Internet Explorer\Low Rights\ElevationPolicy\{E62A7A31-6025-408E-87F6-81AEB0DC9347}]
"AppName"="vsjitdebugger.exe"
"AppPath"="C:\\Windows\\system32\\"
"Policy"=dword:00000023

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\Debugger\JIT]
".NET Debugger"="\"C:\\Windows\\system32\\vsjitdebugger.exe\" PID %d APPDOM %d EXTEXT \"%s\" EVTHDL %d"
"Native Debugger"="\"C:\\Windows\\system32\\vsjitdebugger.exe\" -p %ld -e %ld -j 0x%p"
"Default DbgJITDebugLaunchSetting"=dword:00000010
"Host Path"="C:\\Windows\\system32\\vsjitdebugger.exe"

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\SharedDlls]
"C:\\Windows\\system32\\vsjitdebugger.exe"=dword:00000002

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug]
"UserDebuggerHotKey"=dword:00000000
"Debugger"="\"C:\\Windows\\system32\\vsjitdebugger.exe\" -p %ld -e %ld -j 0x%p"

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug\AutoExclusionList]
"DWM.exe"=dword:00000001

[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\EventLog\Application\VsJITDebugger]
"EventMessageFile"="C:\\Windows\\system32\\vsjitdebugger.exe"
"TypesSupported"=dword:00000007

[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\Services\EventLog\Application\VsJITDebugger]
"EventMessageFile"="C:\\Windows\\system32\\vsjitdebugger.exe"
"TypesSupported"=dword:00000007

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\Application\VsJITDebugger]
"EventMessageFile"="C:\\Windows\\system32\\vsjitdebugger.exe"
"TypesSupported"=dword:00000007

(完)