我正在调查我的一个应用程序中发生的崩溃:我发现这是因为我正在订阅 EventLog.EntryWritten
事件来监视 EntryWritten< 的事件日志
事件。我一直在查看 Reflector 中的 EventLog
类,并跟踪 WinDBG 中的调用堆栈以查看我的应用程序在哪里失败。首先,这里是 WinDBG 中 !eestack 的输出,围绕我的应用程序失败的地方:
0632e620 74c9e900 mscorwks!StrongNameErrorInfo+0x103e4, calling mscorwks!GetMetaDataInternalInterface+0x7f70
0632e694 74c9e855 mscorwks!StrongNameErrorInfo+0x10339, calling mscorwks+0x31c0
0632e6a0 74215058 (MethodDesc 0x7402b7c4 +0x18 System.Security.CodeAccessPermission.RevertAssert()), calling (MethodDesc 0x740c84fc +0 System.Security.SecurityRuntime.RevertAssert(System.Threading.StackCrawlMark ByRef))
0632e6ac 73df4598 (MethodDesc 0x738bc65c +0xa0 System.Diagnostics.SharedUtils.CreateSafeWin32Exception(Int32)), calling (MethodDesc 0x7402b7c4 +0 System.Security.CodeAccessPermission.RevertAssert())
0632e6e4 73ee6fa0 (MethodDesc 0x738e064c System.Diagnostics.EventLog.get_OldestEntryNumber()), calling mscorwks!StrongNameErrorInfo+0x1031b
0632e6f4 73df24ed (MethodDesc 0x738e06e8 +0x1bd System.Diagnostics.EventLog.CompletionCallback(System.Object)), calling (MethodDesc 0x738e064c +0 System.Diagnostics.EventLog.get_OldestEntryNumber())
0632e728 74bb8cef mscorwks!CoUninitializeEE+0x5687, calling mscorwks!CoUninitializeEE+0x5613
0632e73c 73df0fe4 (MethodDesc 0x738e096c +0x94 System.Diagnostics.EventLog.StaticCompletionCallback(System.Object, Boolean)), calling 739443d4
根据我在 Reflector 中看到的,大致遵循 OldestEntryNumber
的 get 访问器的一部分:
if (!UnsafeNativeMethods.GetOldestEventLogRecord(this.readHandle, number))
{
throw SharedUtils.CreateSafeWin32Exception();
}
这个 Win32Exception
是导致我的应用程序崩溃的原因。查看 UnsafeNativeMethods.GetOldestEventLogRecord(...)
方法:
[DllImport("advapi32.dll", CharSet=CharSet.Unicode, SetLastError=true)]
public static extern bool GetOldestEventLogRecord(SafeHandle hEventLog, int[] number);
所以我猜我的问题是两件事之一:
GetOldestEventLogRecord(...)
方法由于某种原因失败。- 系统无法访问/加载 advapi32.dll。这就是为什么我在 !eestack 的输出中看到
StrongNameErrorInfo+0x1031b
的原因吗?
对此的任何想法或帮助都会非常有帮助和感激!
最佳答案
你 P/Invoke 似乎是错误的。
尝试将其更改为:
[DllImport ("advapi32.dll", SetLastError=true)]
public static extern int GetOldestEventLogRecord (IntPtr hEventLog, ref int OldestRecord);
顺便说一下,还有一种检索这些信息的替代方法:使用托管的 EventLog 类。
System.Diagnostics.EventLogEntryCollection
关于C#应用程序崩溃原因,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8897512/