C # Reason for application crash

I am studying a failure in one of my applications: I found out that this is due to the fact that I subscribe to the EventLog.EntryWritten event to track the event log for EntryWritten events. I looked at the EventLog class in Reflector and after the call stack in WinDBG to see where my application fails. First of all, here is the output of Eestack in WinDBG, where my application fails:

 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 

Roughly following this, from what I see in Reflector, here is part of the get accessor for OldestEntryNumber :

 if (!UnsafeNativeMethods.GetOldestEventLogRecord(this.readHandle, number)) { throw SharedUtils.CreateSafeWin32Exception(); } 

This is a Win32Exception - this is what causes my application to crash. Looking at the UnsafeNativeMethods.GetOldestEventLogRecord(...) method:

 [DllImport("advapi32.dll", CharSet=CharSet.Unicode, SetLastError=true)] public static extern bool GetOldestEventLogRecord(SafeHandle hEventLog, int[] number); 

So, I assume that my problem is either one of two things:

  • For some reason, the GetOldestEventLogRecord(...) method does not work.
  • The system cannot receive / download advapi32.dll file. Maybe that's why I see StrongNameErrorInfo+0x1031b , where it can call this method in the output! Estack?

Any ideas or help on this would be really helpful and appreciated!

+4
source share
1 answer

You P / Invoke seems to be mistaken.

Try changing it to:

 [DllImport ("advapi32.dll", SetLastError=true)] public static extern int GetOldestEventLogRecord (IntPtr hEventLog, ref int OldestRecord); 

By the way, there is an alternative way to get this information: using the EventLog managed classes.

 System.Diagnostics.EventLogEntryCollection 
0
source

Source: https://habr.com/ru/post/1391483/


All Articles