I'm want to get c# object inclusive size by using clrmd API.
In order to get this information, first I need to attach to the process.
To achieve this, I'm using DataTarget.CreateSnapshotAndAttach
method.
For some reason, the application crash after getting System.Runtime.InteropServices.SEHException
exception with 0x80004005 Error Code
StackTrace:
at Microsoft.Win32.SafeNativeMethods.CloseHandle(IntPtr handle)
at Microsoft.Win32.SafeHandles.SafeProcessHandle.ReleaseHandle()
at System.Runtime.InteropServices.SafeHandle.InternalFinalize()
at System.Runtime.InteropServices.SafeHandle.Dispose(Boolean disposing)
at System.Runtime.InteropServices.SafeHandle.Finalize()
The root cause for this problem is an exception from the GC Finalizer Thread.
How can I bypass or prevent this exception?
Full code example:
public static void Main(string[] args)
{
var processId = Process.GetCurrentProcess().Id;
using (var dataTarget = DataTarget.CreateSnapshotAndAttach(processId))
{
}
GC.Collect();
GC.WaitForPendingFinalizers(); // Will cause exception
}
Update: When I "Start Without Debugging", I don't get the exception. But I want to debug.
clrmd fix it and support it from version 1.1.57604.