1

例外をスローしている ac# Windows サービスがあります。
windbg を使用してこのサービスを起動し、例外がスローされるまで実行させました。

デバッガーが停止したら、次のことを行います。

  1. 優先_dml 1
  2. !スレッド。 これによりスレッドが出力され、問題の例外をクリックします。
  3. _messageをクリックすると、次のように表示されます。

    0:018> !DumpObj /d 0105e134 名前: System.String MethodTable: 79b9f9ac EEClass: 798d8bb0 サイズ: 120 (0x78) バイト ファイル: C:\WINDOWS\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0. 0__b77a5c561934e089\mscorlib.dll 文字列: オブジェクト参照がオブジェクトのインスタンスに設定されていません。

  4. 次に、 !clrstackを実行して、次の結果を取得します。

    06f8e090 04d48299 AD.Intellex.DriverService.ServerComponentManager.StopCrossFire() 06f8e098 04d48214 AD.Intellex.DriverService.WindowsService.OnStop() 76b5e8\System.ServiceProcess.ni.dll 06f8e108 04d48177 AD.Intellex.DriverService.WindowsService. UnhandledExceptionEventHandler (System.Object, System.UnhandledExceptionEventArgs) 06f8e4cc 791421db [GCFrame: 06f8e4cc] 06f8e568 791421db [GCFrame: 06f8e568] 06f8e63c 791421db [GCFrame: 06f8e63c] 06f8e740 791421db [GCFrame: 06f8e740] 06f8f234 791421db [HelperMethodFrame_PROTECTOBJ: 06f8f234] System.Runtime.CompilerServices .RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup (TryCode、CleanupCode、System.Object) 06f8ec78 04d47f23 AD.HardwareInterface.IntellexHardwareInterface.ObjectProcessor. CameraAlarmActivate(Int32, SoftwareHouse.CrossFire.Common.DataServiceLayer.DataServiceObject, AD.Common.VideoObjectDefinitions.CameraAlertStatus, Boolean, System.DateTime, System.Collections.Generic.Dictionary`2 ByRef) 06f8edb8 04d46db3 AD.HardwareInterface.IntellexHardwareInterface.IntellexProcessor.ProcessCameraAlarm( System.Object) 06f8edf4 79b2d871 System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(System.Object) 06f8edfc 79ab4db5 System.Threading.ExecutionContext.runTryCode(System.Object) 06f8f234 791421db [HelperMethodFrame_PROTECTOBJ: 06f8f234] System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode 、CleanupCode、System.Object) 06f8f298 79ab4cba System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext、System.Threading.ContextCallback、System.Object) 06f8f2b0 79ab7fc2 System.Threading。ExecutionContext.Run(System.Threading.ExecutionContext、System.Threading.ContextCallback、System.Object、Boolean) 06f8f2d4 79af2b66 System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() 06f8f2e8 79af23f3 System.Threading.ThreadPoolWorkQueue.Dispatch() 06f8f334 79af2299 System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() 06f8f6f4 791421db [DebuggerU2MCatchHandlerFrame: 06f8f6f4]06f8f6f4]06f8f6f4]

方法を読むと、例外をスローする関数がObjectProcessor.CameraAlarmActivateであることがわかります

この関数のコードは次のとおりです。

 public override void CameraAlarmActivate(int cameraNumber, DataServiceObject dso, AD.Common.VideoObjectDefinitions.CameraAlertStatus status, bool isBegin, DateTime time, out Dictionary<string, object> msgFormatParameters)
    {
        msgFormatParameters = null;
        try
        {   
            _alarmMutex.WaitOne();
            Type type = TypeManager.Instance["SoftwareHouse.NextGen.Common.SecurityObjects.VideoCamera"];
            if (type == null) return;

            DataServiceObject camera = ClientServerConnection.Instance.FindObject(type, "Number = ? AND ServerID = ?", new object[] { cameraNumber, (int)dso[CameraKey.ObjectID] }, true) as DataServiceObject;
            if (camera != null)
            {
                string alert = status.ToString();
                List<string> alarmList = CheckIntellexCameraContainer(camera, dso, alert);

                if(alarmList != null && alarmList.Count > 0)
                {
                    bool alarmToJournal = false;
                    // If alarm is Motion...
                    if (status == AD.Common.VideoObjectDefinitions.CameraAlertStatus.Motion && alarmList.Contains("motion"))
                    {
                        alarmToJournal = true;
                        if (isBegin)
                        {
                            // Set the Motion property to true.
                            camera["Motion"] = true;
                            ClientServerConnection.Instance.UpdateObject(camera.ObjectKey, new string[] { "Motion" }, new object[] { true });                                
                        }
                        else
                        {
                            // Set the Motion property to false.
                            camera["Motion"] = false;
                            ClientServerConnection.Instance.UpdateObject(camera.ObjectKey, new string[] { "Motion" }, new object[] { false });
                        }
                    }

                    // If alarm is VideoLoss...
                    if (status == AD.Common.VideoObjectDefinitions.CameraAlertStatus.VideoLoss && alarmList.Contains(status.ToString().ToLower()))
                    {
                        alarmToJournal = true;
                        if (isBegin)
                        {
                            // Set the Videoloss property to true.
                            camera[CameraKey.Videoloss] = true;
                            ClientServerConnection.Instance.UpdateObject(camera.ObjectKey, new string[] { CameraKey.Videoloss }, new object[] { true });
                        }
                        else
                        {
                            // Set the Videoloss property to false;
                            camera[CameraKey.Videoloss] = false;
                            ClientServerConnection.Instance.UpdateObject(camera.ObjectKey, new string[] { CameraKey.Videoloss }, new object[] { false });
                        }
                    }

                    // If alarm is Light...
                    if (status == AD.Common.VideoObjectDefinitions.CameraAlertStatus.LightChange && alarmList.Contains("light"))
                    {
                        alarmToJournal = true;
                        if (isBegin)
                        {
                            // Set the Light property to true.
                            camera["Light"] = true;
                            ClientServerConnection.Instance.UpdateObject(camera.ObjectKey, new string[] { "Light" }, new object[] { true });
                        }
                        else
                        {
                            // Set the Light property to false;
                            camera["Light"] = false;
                            ClientServerConnection.Instance.UpdateObject(camera.ObjectKey, new string[] { "Light" }, new object[] { false });
                        }
                    }

                    // If alarm is Perimeter...
                    if (status == AD.Common.VideoObjectDefinitions.CameraAlertStatus.PerimeterProtection && alarmList.Contains("perimeter"))
                    {
                        alarmToJournal = true;
                        if (isBegin)
                        {
                            // Set the Perimeter property to true.
                            camera["Perimeter"] = true;
                            ClientServerConnection.Instance.UpdateObject(camera.ObjectKey, new string[] { "Perimeter" }, new object[] { true });
                        }
                        else
                        {
                            // Set the Light property to false;
                            camera["Perimeter"] = false;
                            ClientServerConnection.Instance.UpdateObject(camera.ObjectKey, new string[] { "Perimeter" }, new object[] { false });
                        }
                    }

                    // If alarm is AlarmIn(DryContact)...
                    if ((status == AD.Common.VideoObjectDefinitions.CameraAlertStatus.ExternalAlarm || status == AD.Common.VideoObjectDefinitions.CameraAlertStatus.DryContact) && alarmList.Contains("alarmin"))
                    {
                        alarmToJournal = true;
                        if (isBegin)
                        {
                            // Set the AlarmIn property to true.
                            camera["Alarmin"] = true;
                            ClientServerConnection.Instance.UpdateObject(camera.ObjectKey, new string[] { "Alarmin" }, new object[] { true });
                        }
                        else
                        {
                            // Set the AlarmIn property to false;
                            camera["Alarmin"] = false;
                            ClientServerConnection.Instance.UpdateObject(camera.ObjectKey, new string[] { "Alarmin" }, new object[] { false });
                        }
                    }

                    if(alarmToJournal)
                        msgFormatParameters = CreateMessageParameters(status, camera, dso, time);
                }
            }
        }  
        catch (Exception)
        {
        }
        finally
        {
            _alarmMutex.ReleaseMutex();
        }
    }

この関数をデバッガーで確認したいので、!clrstack の出力から関数の IP 値を選択します。(04d47f23)

私は以下を取得します:

0:018> !U /d 04d47f23
Normal JIT generated code
 AD.HardwareInterface.IntellexHardwareInterface.ObjectProcessor.CameraAlarmActivate(Int32, SoftwareHouse.CrossFire.Common.DataServiceLayer.DataServiceObject, AD.Common.VideoObjectDefinitions.CameraAlertStatus, Boolean, System.DateTime, System.Collections.Generic.Dictionary`2<System.String,System.Object> ByRef)
Begin 04d474d0, size a79
04d474d0 55              push    ebp
04d474d1 8bec            mov     ebp,esp
04d474d3 57              push    edi
04d474d4 56              push    esi
04d474d5 53              push    ebx
04d474d6 81ec10010000    sub     esp,110h
04d474dc 8bf1            mov     esi,ecx
04d474de 8dbd78ffffff    lea     edi,[ebp-88h]
04d474e4 b91e000000      mov     ecx,1Eh
04d474e9 33c0            xor     eax,eax
04d474eb f3ab            rep stos dword ptr es:[edi]
04d474ed 8bce            mov     ecx,esi
04d474ef 33c0            xor     eax,eax
04d474f1 8945e8          mov     dword ptr [ebp-18h],eax
04d474f4 898d74ffffff    mov     dword ptr [ebp-8Ch],ecx
04d474fa 8bfa            mov     edi,edx
04d474fc 8b5d18          mov     ebx,dword ptr [ebp+18h]
04d474ff 8b4508          mov     eax,dword ptr [ebp+8]
04d47502 33d2            xor     edx,edx
04d47504 8910            mov     dword ptr [eax],edx
04d47506 8b8574ffffff    mov     eax,dword ptr [ebp-8Ch]
04d4750c 8b4834          mov     ecx,dword ptr [eax+34h]
04d4750f 8b01            mov     eax,dword ptr [ecx]
04d47511 8b402c          mov     eax,dword ptr [eax+2Ch]
04d47514 ff500c          call    dword ptr [eax+0Ch]
04d47517 e8d4ad4bfe      call    032022f0 (SoftwareHouse.CrossFire.Common.Core.TypeManager.get_Instance(), mdToken: 010ACF2C)
04d4751c 8bc8            mov     ecx,eax
04d4751e 8b158c28b501    mov     edx,dword ptr ds:[1B5288Ch] ("SoftwareHouse.NextGen.Common.SecurityObjects.VideoCamera")
04d47524 3909            cmp     dword ptr [ecx],ecx
04d47526 e8e5d04bfe      call    03204610 (SoftwareHouse.CrossFire.Common.Core.TypeManager.get_Item(System.String), mdToken:     010ACF2C)
04d4752b 8945dc          mov     dword ptr [ebp-24h],eax
04d4752e 8bc8            mov     ecx,eax
04d47530 33d2            xor     edx,edx
04d47532 e853134274      call    clr!RuntimeTypeHandle::TypeEQ (7916888a)
04d47537 85c0            test    eax,eax
04d47539 7418            je      <Unloaded_avcodec-53.dll>+0x8e7553 (04d47553)
04d4753b c745e400000000  mov     dword ptr [ebp-1Ch],0
04d47542 c745e8fc000000  mov     dword ptr [ebp-18h],0FCh
04d47549 68377fd404      push    offset <Unloaded_avcodec-53.dll>+0x8e7f37 (04d47f37)
04d4754e e9c7090000      jmp     <Unloaded_avcodec-53.dll>+0x8e7f1a (04d47f1a)
04d47553 e878ca4bfe      call    03203fd0 (SoftwareHouse.CrossFire.Common.ClientInterfaceLayer.ClientServerConnection.get_Instance(), mdToken: 010ACF2C)
04d47558 898534ffffff    mov     dword ptr [ebp-0CCh],eax
04d4755e ba02000000      mov     edx,2
04d47563 b9e2428879      mov     ecx,offset mscorlib_ni+0x42e2 (798842e2)
04d47568 e853acc3fb      call    009821c0 (JitHelp: CORINFO_HELP_NEWARR_1_OBJ)
04d4756d 89856cffffff    mov     dword ptr [ebp-94h],eax
04d47573 b97829ba79      mov     ecx,offset mscorlib_ni+0x322978 (79ba2978) (MT:   System.Int32)
04d47578 e8a3aac3fb      call    00982020 (JitHelp: CORINFO_HELP_NEWSFAST)
04d4757d 8bf0            mov     esi,eax
04d4757f 8b856cffffff    mov     eax,dword ptr [ebp-94h]
04d47585 8945b0          mov     dword ptr [ebp-50h],eax
04d47588 897e04          mov     dword ptr [esi+4],edi
04d4758b 56              push    esi
04d4758c 8b8d6cffffff    mov     ecx,dword ptr [ebp-94h]
04d47592 33d2            xor     edx,edx
04d47594 e8fb584574      call    clr!JIT_Stelem_Ref (7919ce94)
04d47599 8b15002ab501    mov     edx,dword ptr ds:[1B52A00h] ("ObjectID")
04d4759f 8b4d1c          mov     ecx,dword ptr [ebp+1Ch]
04d475a2 8b01            mov     eax,dword ptr [ecx]
04d475a4 8b4034          mov     eax,dword ptr [eax+34h]
04d475a7 ff5014          call    dword ptr [eax+14h]
04d475aa 8bf8            mov     edi,eax
04d475ac 813f7829ba79    cmp     dword ptr [edi],offset mscorlib_ni+0x322978 (79ba2978)
04d475b2 740c            je      <Unloaded_avcodec-53.dll>+0x8e75c0 (04d475c0)
04d475b4 8bd7            mov     edx,edi
04d475b6 b97829ba79      mov     ecx,offset mscorlib_ni+0x322978 (79ba2978) (MT: System.Int32)
04d475bb e85e614274      call    clr!JIT_Unbox (7916d71e)
04d475c0 b97829ba79      mov     ecx,offset mscorlib_ni+0x322978 (79ba2978) (MT: System.Int32)
04d475c5 e856aac3fb      call    00982020 (JitHelp: CORINFO_HELP_NEWSFAST)
04d475ca 8bf0            mov     esi,eax
04d475cc 8b856cffffff    mov     eax,dword ptr [ebp-94h]
04d475d2 8945ac          mov     dword ptr [ebp-54h],eax
04d475d5 8b4704          mov     eax,dword ptr [edi+4]
04d475d8 894604          mov     dword ptr [esi+4],eax
04d475db 56              push    esi
04d475dc 8b8d6cffffff    mov     ecx,dword ptr [ebp-94h]
04d475e2 ba01000000      mov     edx,1
04d475e7 e8a8584574      call    clr!JIT_Stelem_Ref (7919ce94)
04d475ec 8b8534ffffff    mov     eax,dword ptr [ebp-0CCh]
04d475f2 3900            cmp     dword ptr [eax],eax
04d475f4 ff358833b101    push    dword ptr ds:[1B13388h] ("Number = ? AND ServerID = ?")
04d475fa ffb56cffffff    push    dword ptr [ebp-94h]
04d47600 6a01            push    1
04d47602 6a00            push    0
04d47604 8b55dc          mov     edx,dword ptr [ebp-24h]
04d47607 8bc8            mov     ecx,eax
04d47609 ff15c05a9900    call    dword ptr ds:[995AC0h] (SoftwareHouse.CrossFire.Common.ClientInterfaceLayer.ClientServerConnection.FindObject(System.Type, System.String, System.Object[], Boolean, SoftwareHouse.CrossFire.Common.Core.RemoteProxyOption), mdToken: 010ACF2C)
04d4760f 8bd0            mov     edx,eax
04d47611 b9a0576e03      mov     ecx,36E57A0h (MT: SoftwareHouse.CrossFire.Common.DataServiceLayer.DataServiceObject)
04d47616 e8b7584574      call    clr!JIT_IsInstanceOfClass (7919ced2)
04d4761b 8bf8            mov     edi,eax
04d4761d 85ff            test    edi,edi
04d4761f 0f84e0080000    je      <Unloaded_avcodec-53.dll>+0x8e7f05 (04d47f05)
04d47625 b918889503      mov     ecx,3958818h (MT: AD.Common.VideoObjectDefinitions.CameraAlertStatus)
04d4762a e8f1a9c3fb      call    00982020 (JitHelp: CORINFO_HELP_NEWSFAST)
04d4762f 8bf0            mov     esi,eax

これから、何が例外をスローしているのかを知る方法はありますか???

4

1 に答える 1

2

デバッガーで例外をキャッチし、「CameraAlarmActivate」という名前のメソッドによって例外がスローされていることを確認したので、メソッドの先頭にブレークポイントを設定し、例外がヒットするまでそれをステップスルーできます。その後、変数を検査し、それに応じてトラブルシューティングを行うことができます。

Exception オブジェクトから、より多くの情報を取得することもできます。

// Get stack trace for the exception with source file information
var st = new StackTrace(ex, true);
// Get the top stack frame
var frame = st.GetFrame(0);
// Get the line number from the stack frame
var line = frame.GetFileLineNumber();

ここから: C# - 例外をスローした行番号を取得

エラーが見過ごされる可能性があるため、一般に、空の例外ハンドラーを使用することはあまり良い方法ではありません。少なくともログ ライブラリを統合して、アプリケーションが独自のログ ファイルを持ち、すべての例外からエラー ログ エントリを書き込むことをお勧めします。エラーが発生した後、ログ ファイルを介してアプリケーションの状態を追跡するのに役立つ他の詳細なタイプのログを書き込むこともできます。これは、Windows サービスや、どこでもエラーが発生する可能性のあるバックグラウンド ベースのジョブで特に役立ちます。Log4net は、使いやすい優れたロギング ライブラリです: http://logging.apache.org/log4net/

それ以外に、コードをざっと見てみると、クライアント接続がある時点で切断され、ClientServerConnection または ClientServerConnection.Instance がある時点で NULL になる可能性があるという大雑把な推測になります。これは、例外ブロック内でできることの良い例です。その特定の例外をキャッチしてから、再接続して再試行できます。

最後に、その関数をより詳細にデバッグするために特定のシンボルが不足している場合や、アンマネージ コードでのデバッグに関連するプロジェクトのオプションの一部を有効にする必要がある場合があります。

于 2013-07-23T22:57:51.110 に答える