I have a WinForms application and added AppCenter Crashes Tracking support.
I have also added Crashes delegates Crashes.ShouldProcessErrorReport, Crashes.SendingErrorReport, Crashes.SentErrorReport, Crashes.FailedToSendErrorReport.
and log them to a text file to make sure they are called. For test pursposes I cause an unhandled exception by throwing a StackOverflowException
.
When debugging the program under Visual Studio everything works OK, logs are written to the text file, and crashes are sent to AppCenter server. When running directly debug executable delegates are not called and crashes are not sent. I have checked and Crashes API is enabled.
Crashes.ShouldProcessErrorReport = (ErrorReport report) =>
{
DataLogger.Error("AppCenter process error");
return true; // return true if the crash report should be processed, otherwise false.
};
Crashes.SendingErrorReport += (object sender, SendingErrorReportEventArgs e) =>
{
// Your code, e.g. to present a custom UI.
string s = e.Report.Exception.StackTrace;
Console.WriteLine(s);
DataLogger.Error("AppCenter sending ", e.Report.Exception);
};
Crashes.SentErrorReport += (object sender, SentErrorReportEventArgs e) => {
// Your code, e.g. to hide a custom UI.
DataLogger.Error("Appcenter successfully sent a crash");
};
Crashes.FailedToSendErrorReport += (object sender, FailedToSendErrorReportEventArgs e) => {
// Your code goes here.
string s = e.Exception.ToString();
Console.WriteLine(s);
DataLogger.Error("AppCenter failed to send " + s);
};
AppCenter.Start("SECRET_KEY", typeof(Analytics), typeof(Crashes));
bool isEnabled = Crashes.IsEnabledAsync().Result;
DataLogger.Error("AppCeneter enabled " + isEnabled);
Application.Run(new MyForm());
Make sure you've read the documentation on how WinForms handles crashes differently. Unless you've disabled default WinForms behavior, with the following line of code, it doesn't truly crash.
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException);
Additionally, StackOverFlowExceptions have some special behavior, for example:
“Starting with the .NET Framework version 2.0, a StackOverflowException object cannot be caught by a try-catch block and the corresponding process is terminated by default.”
It might be that it behaves differently when the debugger is attached as part of the special behavior. Even after allowing WinForms to crash, you might need to try with a different type of exception that does not have special rules. And in fact, a specific function is provided to accomplish this:
Crashes.GenerateTestCrash();