jirentabu / crashrpt

Automatically exported from code.google.com/p/crashrpt
0 stars 0 forks source link

Using crashrpt with C# application doesn't catch the exceptions. #146

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hello Sir,
I want to use crash report with my simple c# application.
For that, I created a dll that has a function that can be called from c# code. 
That function registers the crash handlers.

It executed fine, without any error but did not catch the crash.

Here's my function. 
---------------------------------------------------------------------
extern "C" __declspec(dllexport) void LoadCrashHandlers()
{
    HRESULT hRes = ::CoInitialize(NULL);
    // If you are running on NT 4.0 or higher you can use the following call instead to 
    // make the EXE free threaded. This means that calls come in on a random RPC thread.
    //  HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
    ATLASSERT(SUCCEEDED(hRes));

    // Install crash reporting

    CR_INSTALL_INFO info;
    memset(&info, 0, sizeof(CR_INSTALL_INFO));
    info.cb = sizeof(CR_INSTALL_INFO);  
    info.pszAppName = _T("CrashRpt Tests"); // Define application name.
    //info.pszAppVersion = _T("1.2.7");     // Define application version.
    info.pszEmailSubject = _T("Error from CrashRptTests"); // Define subject for email.
    info.pszEmailTo = _T("test@hotmail.com");   // Define E-mail recipient address.  
    info.pszUrl = _T("http://localhost:80/crashrpt.php"); // URL for sending reports over HTTP.     
    info.pfnCrashCallback = CrashCallback; // Define crash callback function.   
    // Define delivery transport priorities. 
    info.uPriorities[CR_HTTP] = 3;         // Use HTTP the first.
    info.uPriorities[CR_SMTP] = 2;         // Use SMTP the second.
    info.uPriorities[CR_SMAPI] = 1;        // Use Simple MAPI the last.  
    info.dwFlags = 0;                    
    info.dwFlags |= CR_INST_ALL_POSSIBLE_HANDLERS; // Install all available exception handlers.
    info.dwFlags |= CR_INST_HTTP_BINARY_ENCODING;   // Use binary encoding for HTTP uploads (recommended).  
    info.dwFlags |= CR_INST_APP_RESTART;            // Restart the application on crash.  
    //info.dwFlags |= CR_INST_NO_MINIDUMP;            // Do not include minidump.
    //info.dwFlags |= CR_INST_NO_GUI;               // Don't display GUI.
    //info.dwFlags |= CR_INST_DONT_SEND_REPORT;     // Don't send report immediately, just queue for later delivery.
    //info.dwFlags |= CR_INST_STORE_ZIP_ARCHIVES;   / Store ZIP archives along with uncompressed files (to be used with CR_INST_DONT_SEND_REPORT)
    info.dwFlags |= CR_INST_SEND_QUEUED_REPORTS;    // Send reports that were failed to send recently.
    info.pszDebugHelpDLL = NULL;                    // Search for dbghelp.dll using default search sequence.
    info.uMiniDumpType = MiniDumpNormal;            // Define minidump size.
    // Define privacy policy URL.
    info.pszPrivacyPolicyURL = _T("http://code.google.com/p/crashrpt/wiki/PrivacyPolicyTemplate");
    info.pszErrorReportSaveDir = NULL;       // Save error reports to the default location.
    info.pszRestartCmdLine = _T("/restart"); // Command line for automatic app restart.
    //info.pszLangFilePath = _T("D:\\");       // Specify custom dir or filename for language file.
    //info.pszSmtpProxy = _T("127.0.0.1:2525");  // Use SMTP proxy.
    CString sCustomSenderIcon = GetModulePath(NULL);
#ifdef _DEBUG
    //sCustomSenderIcon += _T("\\CrashRptTestd.exe, -203"); // Use custom icon
#else
    //sCustomSenderIcon += _T("\\CrashRptTest.exe, -203"); // Use custom icon
#endif
    //info.pszCustomSenderIcon = sCustomSenderIcon.GetBuffer(0);

    // Install crash handlers.
    CrAutoInstallHelper cr_install_helper(&info);
    if(cr_install_helper.m_nInstallStatus!=0)
    {
        TCHAR buff[256];
        crGetLastErrorMsg(buff, 256);
        MessageBox(NULL, buff, _T("crInstall error"), MB_OK);
        return;
    }
    ATLASSERT(cr_install_helper.m_nInstallStatus==0); 

    CString sLogFile = GetAppDir() + _T("\\dummy.log");
    CString sIniFile = GetAppDir() + _T("\\dummy.ini");

    int nResult = crAddFile2(sLogFile, NULL, _T("Dummy Log File"), CR_AF_MAKE_FILE_COPY);
    ATLASSERT(nResult==0);

    nResult = crAddFile(sIniFile, _T("Dummy INI File"));
    ATLASSERT(nResult==0);

    nResult = crAddScreenshot2(CR_AS_PROCESS_WINDOWS|CR_AS_USE_JPEG_FORMAT, 10);
    //nResult = crAddScreenshot(CR_AS_MAIN_WINDOW);
    ATLASSERT(nResult==0);

    nResult = crAddProperty(_T("VideoCard"),_T("nVidia GeForce 9800"));
    ATLASSERT(nResult==0);

    nResult = crAddRegKey(_T("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer"), _T("regkey.xml"), 0);
    ATLASSERT(nResult==0);

    nResult = crAddRegKey(_T("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"), _T("regkey.xml"), 0);
    ATLASSERT(nResult==0);
    return;
}
---------------------------------------------------------------------

It's called from c# via this code.

[DllImport("CrashHandlerRegistrar.dll", EntryPoint = "LoadCrashHandlers")]
extern public static void LoadCrashHandlers();

public Form1()
{
    InitializeComponent();
    LoadCrashHandlers();
}

Here's the crashing function, after handler is loaded.

private void button1_Click(object sender, EventArgs e)
{
    sender = null;
    sender.GetType(); //////// CRASH!!!!!! But not caught !!! ////////
}

Can you guide me on why it's not catching the crash.
Thanks a lot,
Mohan

What is the expected output? What do you see instead?
Exception should be caught

What version of CrashRpt are you using?
1.3.0

What is your version of Visual Studio?
VS 2010

What is your version of Windows operating system?
Win Vista

Please see the attached video to get the clear idea.

Original issue reported on code.google.com by mohan848...@gmail.com on 4 May 2012 at 10:34

Attachments:

GoogleCodeExporter commented 9 years ago
I'm afraid you can't use CrashRpt with a C# application, because .NET framework 
uses different exception handling model than C++. Instead you can try to use 
SOS debugging extension to generate a minidump and windbg to post-process it.

Original comment by zexspect...@gmail.com on 4 May 2012 at 12:15

GoogleCodeExporter commented 9 years ago
Hi Thanks a lot for the information.
It would be great if you can suggest me some of the other crash reporting apps 
for handling exceptions in C#.
Also, where can I get the SOS extension application?
Thanks again.
Mohan

Original comment by mohan848...@gmail.com on 28 May 2012 at 6:04

GoogleCodeExporter commented 9 years ago
You may read this one:

http://voneinem-windbg.blogspot.com/2007/03/creating-and-analyzing-minidumps-in-
net.html

Original comment by zexspect...@gmail.com on 26 Aug 2012 at 7:49