@@ -238,17 +457,8 @@ public void Send(Exception exception)
private void Send(Exception exception, bool silent)
{
Exception = exception;
-
- var mainAssembly = Assembly.GetEntryAssembly();
- string appTitle = null;
- var attributes = mainAssembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), true);
- if (attributes.Length > 0)
- {
- appTitle = ((AssemblyTitleAttribute)attributes[0]).Title;
- }
-
- ApplicationTitle = !string.IsNullOrEmpty(appTitle) ? appTitle : mainAssembly.GetName().Name;
- ApplicationVersion = GetClickOnceVersion() ?? mainAssembly.GetName().Version.ToString();
+ CrashDateUtc = DateTime.UtcNow;
+ CaptureApplicationInfo();
try
{
if (CaptureScreen)
@@ -263,15 +473,7 @@ private void Send(Exception exception, bool silent)
if (!AnalyzeWithDoctorDump)
{
- if (string.IsNullOrEmpty(FromEmail))
- {
- throw new ArgumentNullException(@"FromEmail");
- }
-
- if (string.IsNullOrEmpty(SmtpHost))
- {
- throw new ArgumentNullException("SmtpHost");
- }
+ ValidateSmtpSettings();
}
if (!Application.MessageLoop)
@@ -300,6 +502,74 @@ private void Send(Exception exception, bool silent)
}
}
+ private void ValidateSmtpSettings()
+ {
+ if (string.IsNullOrEmpty(FromEmail))
+ {
+ throw new ArgumentNullException(@"FromEmail");
+ }
+
+ if (string.IsNullOrEmpty(SmtpHost))
+ {
+ throw new ArgumentNullException("SmtpHost");
+ }
+ }
+
+ ///
+ /// Whether the crash dialog should send an anonymous report to Doctor Dump as soon as it opens.
+ /// Never when reports are delivered by SMTP only.
+ ///
+ internal bool SendAnonymousReportWhenDialogOpens =>
+ AnalyzeWithDoctorDump && DoctorDumpSettings != null && DoctorDumpSettings.SendAnonymousReportSilently;
+
+ private void CaptureApplicationInfo()
+ {
+ GetApplicationInfo(out ApplicationTitle, out ApplicationVersion);
+ ApplicationAssemblyVersion = Assembly.GetEntryAssembly()?.GetName().Version?.ToString();
+ }
+
+ private static void GetApplicationInfo(out string title, out string version)
+ {
+ var mainAssembly = Assembly.GetEntryAssembly();
+ if (mainAssembly == null)
+ {
+ title = FailedReportQueue.GetApplicationName();
+ version = GetClickOnceVersion() ?? string.Empty;
+ return;
+ }
+
+ string appTitle = null;
+ var attributes = mainAssembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), true);
+ if (attributes.Length > 0)
+ {
+ appTitle = ((AssemblyTitleAttribute)attributes[0]).Title;
+ }
+
+ title = !string.IsNullOrEmpty(appTitle) ? appTitle : mainAssembly.GetName().Name;
+ version = GetClickOnceVersion() ?? mainAssembly.GetName().Version.ToString();
+ }
+
+ private void OpenReportInBrowser(string reportUrl)
+ {
+ if (DoctorDumpSettings != null && DoctorDumpSettings.OpenReportInBrowser && !string.IsNullOrEmpty(reportUrl))
+ ReportUrlOpener(reportUrl);
+ }
+
+ ///
+ /// Opening the problem page is optional: failing to do so (e.g. no default browser) never affects delivery.
+ ///
+ private void TryOpenReportInBrowser(string reportUrl)
+ {
+ try
+ {
+ OpenReportInBrowser(reportUrl);
+ }
+ catch (Exception e)
+ {
+ Debug.WriteLine(e);
+ }
+ }
+
private static string GetClickOnceVersion()
{
#if NETFRAMEWORK
@@ -352,23 +622,9 @@ private void SendEmail(bool includeScreenshot, SendCompletedEventHandler smtpCli
subject = $"{ApplicationTitle} {ApplicationVersion} Crash Report";
}
- var smtpClient = new SmtpClient
- {
- Host = SmtpHost,
- Port = Port,
- EnableSsl = EnableSSL,
- DeliveryMethod = SmtpDeliveryMethod.Network,
- UseDefaultCredentials = false,
- Credentials = new NetworkCredential(UserName, Password)
- };
-
- var message = new MailMessage(new MailAddress(FromEmail), new MailAddress(ToEmail))
- {IsBodyHtml = true, Subject = subject, Body = CreateHtmlReport(userMessage)};
-
- if (ScreenShotBinary?.Length > 0 && includeScreenshot)
- {
- message.Attachments.Add(new Attachment(new MemoryStream(ScreenShotBinary), "Screenshot.png", "image/png"));
- }
+ var smtpClient = CreateSmtpClient();
+ var message = CreateMailMessage(subject, CreateHtmlReport(userMessage),
+ includeScreenshot ? ScreenShotBinary : null);
if (smtpClientSendCompleted != null)
{
@@ -388,11 +644,50 @@ private void SendEmail(bool includeScreenshot, SendCompletedEventHandler smtpCli
}
}
+ private SmtpClient CreateSmtpClient()
+ {
+ return new SmtpClient
+ {
+ Host = SmtpHost,
+ Port = Port,
+ EnableSsl = EnableSSL,
+ DeliveryMethod = SmtpDeliveryMethod.Network,
+ UseDefaultCredentials = false,
+ Credentials = new NetworkCredential(UserName, Password)
+ };
+ }
+
+ private MailMessage CreateMailMessage(string subject, string htmlReport, byte[] screenshot)
+ {
+ var message = new MailMessage(new MailAddress(FromEmail), new MailAddress(ToEmail))
+ {IsBodyHtml = true, Subject = subject, Body = htmlReport};
+
+ if (screenshot?.Length > 0)
+ {
+ message.Attachments.Add(new Attachment(new MemoryStream(screenshot), "Screenshot.png", "image/png"));
+ }
+
+ return message;
+ }
+
#endregion
#region HTML Report Generator
- internal string CreateHtmlReport(string userMessage)
+ ///
+ /// Creates the HTML report of the current crash.
+ ///
+ /// Comment entered by the user.
+ /// Embed the screenshot as an inline image, for reports saved to a file.
+ /// E-mails attach the screenshot instead, because many mail clients block inline data images.
+ internal string CreateHtmlReport(string userMessage, bool embedScreenshot = false)
+ {
+ return CreateHtmlReport(ApplicationTitle, ApplicationVersion, Exception, DeveloperMessage, userMessage,
+ embedScreenshot ? ScreenShotBinary : null);
+ }
+
+ internal static string CreateHtmlReport(string applicationTitle, string applicationVersion, Exception exception,
+ string developerMessage, string userMessage, byte[] embeddedScreenshot)
{
string report =
string.Format(
@@ -454,11 +749,11 @@ internal string CreateHtmlReport(string userMessage)
{4}
- ", WebUtility.HtmlEncode(ApplicationTitle),
- WebUtility.HtmlEncode(ApplicationVersion),
+ ", WebUtility.HtmlEncode(applicationTitle),
+ WebUtility.HtmlEncode(applicationVersion),
WebUtility.HtmlEncode(HelperMethods.GetWindowsVersion()),
WebUtility.HtmlEncode(Environment.Version.ToString()),
- CreateReport(Exception));
+ CreateReport(exception));
if (!String.IsNullOrEmpty(userMessage))
{
report += $@"
@@ -472,7 +767,7 @@ internal string CreateHtmlReport(string userMessage)
";
}
- if (!String.IsNullOrEmpty(DeveloperMessage.Trim()))
+ if (!String.IsNullOrEmpty(developerMessage?.Trim()))
{
report += $@"
@@ -480,7 +775,20 @@ internal string CreateHtmlReport(string userMessage)
Developer Message
-
{WebUtility.HtmlEncode(DeveloperMessage.Trim())}
+
{WebUtility.HtmlEncode(developerMessage.Trim())}
+
+ ";
+ }
+
+ if (embeddedScreenshot?.Length > 0)
+ {
+ report += $@"
+
+
+
Screenshot
+
+
+
![]()
";
}
@@ -489,7 +797,7 @@ internal string CreateHtmlReport(string userMessage)
return report;
}
- private string CreateReport(Exception exception)
+ private static string CreateReport(Exception exception)
{
string report = $@"
@@ -522,7 +830,7 @@ private string CreateReport(Exception exception)
{
- WebUtility.HtmlEncode(exception.StackTrace ?? "No stack trace").Replace("\r\n", "
")
+ WebUtility.HtmlEncode(exception.StackTrace ?? "No stack trace").Replace("\r\n", "\n").Replace("\n", "
")
}
";
@@ -593,21 +901,38 @@ private void SendFullReport(bool includeScreenshot,
{
_doctorDumpService = new DrDumpService(WebProxy);
var reportUrl = _doctorDumpService.SendReportSilently(Exception, ToEmail, DoctorDumpSettings?.ApplicationID, DeveloperMessage, from, userMessage, screenshot);
- if (DoctorDumpSettings != null && DoctorDumpSettings.OpenReportInBrowser)
- {
- if (!string.IsNullOrEmpty(reportUrl))
- Process.Start(new ProcessStartInfo(reportUrl) { UseShellExecute = true });
- }
+ OpenReportInBrowser(reportUrl);
}
}
#endregion
- private struct LoadFailedReportResult
+ }
+
+ ///
+ /// Result of .
+ ///
+ public sealed class FailedReportsRetryResult
+ {
+ internal FailedReportsRetryResult(int failedReports, int failedReportsSent)
{
- public Exception Exception;
- public byte[] ScreenShot;
- public FileInfo FileInfo;
+ FailedReports = failedReports;
+ FailedReportsSent = failedReportsSent;
}
+
+ ///
+ /// The amount of failed reports found.
+ ///
+ public int FailedReports { get; }
+
+ ///
+ /// The amount of failed reports sent (and removed from the queue).
+ ///
+ public int FailedReportsSent { get; }
+
+ ///
+ /// Whether any report has been sent.
+ ///
+ public bool AnyReportSent => FailedReportsSent > 0;
}
///
diff --git a/CrashReporter.NET/XmlText.cs b/CrashReporter.NET/XmlText.cs
new file mode 100644
index 0000000..341f001
--- /dev/null
+++ b/CrashReporter.NET/XmlText.cs
@@ -0,0 +1,73 @@
+using System.Text;
+using System.Xml;
+
+namespace CrashReporterDotNET
+{
+ ///
+ /// Helpers for putting arbitrary text (exception messages, user input) into XML.
+ ///
+ internal static class XmlText
+ {
+ private const char ReplacementCharacter = '�';
+
+ ///
+ /// Replaces unpaired surrogates, which cannot be encoded at all, with U+FFFD.
+ /// Other characters that are invalid in XML (e.g. U+0001) are kept; the failed report writer escapes them
+ /// as character references, so they round-trip exactly.
+ ///
+ public static string ReplaceLoneSurrogates(string text)
+ {
+ return Replace(text, false);
+ }
+
+ ///
+ /// Replaces every character that is not allowed in an XML 1.0 document (control characters, U+FFFE, U+FFFF
+ /// and unpaired surrogates) with U+FFFD, so the text can be sent to services that validate XML strictly.
+ ///
+ public static string ToValidXml(string text)
+ {
+ return Replace(text, true);
+ }
+
+ private static string Replace(string text, bool replaceInvalidXmlCharacters)
+ {
+ if (string.IsNullOrEmpty(text))
+ return text;
+
+ StringBuilder builder = null;
+ for (var i = 0; i < text.Length; i++)
+ {
+ var c = text[i];
+ bool valid;
+ if (char.IsHighSurrogate(c))
+ {
+ valid = i + 1 < text.Length && char.IsLowSurrogate(text[i + 1]);
+ if (valid)
+ {
+ builder?.Append(c).Append(text[i + 1]);
+ i++;
+ continue;
+ }
+ }
+ else if (char.IsLowSurrogate(c))
+ {
+ valid = false;
+ }
+ else
+ {
+ valid = !replaceInvalidXmlCharacters || XmlConvert.IsXmlChar(c);
+ }
+
+ if (!valid && builder == null)
+ {
+ builder = new StringBuilder(text.Length);
+ builder.Append(text, 0, i);
+ }
+
+ builder?.Append(valid ? c : ReplacementCharacter);
+ }
+
+ return builder?.ToString() ?? text;
+ }
+ }
+}
diff --git a/CrashReporterWPFTest/App.xaml.cs b/CrashReporterWPFTest/App.xaml.cs
index 34ac298..4a5c55b 100644
--- a/CrashReporterWPFTest/App.xaml.cs
+++ b/CrashReporterWPFTest/App.xaml.cs
@@ -24,7 +24,8 @@ protected override void OnStartup(StartupEventArgs e)
DeveloperMessage = "Retry attempt",
Silent = true
};
- _reportCrash.RetryFailedReports();
+ // Retry reports that could not be sent earlier, in the background so startup is not blocked.
+ _ = _reportCrash.RetryFailedReportsAsync();
}
private void TaskSchedulerOnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs unobservedTaskExceptionEventArgs)
diff --git a/README.md b/README.md
index 8f7f30f..7b1d182 100644
--- a/README.md
+++ b/README.md
@@ -11,6 +11,20 @@ Send crash reports of your desktop application developed using .NET 10 or .NET F
| `net10.0-windows` | Windows Forms and WPF applications on .NET 10. |
| `net48` | Windows Forms and WPF applications on .NET Framework 4.8. |
+### What's new in 2.1
+
+* `RetryFailedReportsAsync(CancellationToken)` retries failed reports without blocking the UI thread. The synchronous `RetryFailedReports()` still works, but blocks until all reports are sent.
+* Failed reports are resent exactly as they were captured, including the original screenshot, application version, developer message and what the user typed. Retrying no longer takes a new screenshot.
+* Failed reports are queued per application in `%TEMP%\CrashReporterNET\\`, with unique file names, and are written atomically. Exception messages containing control characters no longer prevent a report from being saved.
+* E-mail reports, saved HTML reports and the crash dialog show Windows 11 correctly: Windows 11 still reports version 10.0 and its registry product name still says "Windows 10", so the name is now derived from the build number (22000 or later) on workstation editions. Doctor Dump receives the unchanged numeric version (e.g. `10.0.22631`); how its dashboard labels that version is up to the service.
+* Only one retry per application runs at a time, also across processes, so a report is never sent twice by overlapping retries. Each retried report must be delivered within `DeliveryTimeout` (100 seconds by default), and cancelling `RetryFailedReportsAsync` also interrupts an SMTP delivery in progress on .NET Framework.
+* Doctor Dump retries report the application title and version that crashed, not the version running when the report is retried.
+* The *Save report* button embeds the screenshot in the saved HTML file when *Include screenshot* is checked.
+* When `AnalyzeWithDoctorDump` is `false`, the crash dialog no longer sends an anonymous report to Doctor Dump.
+* Doctor Dump responses are validated: HTTP errors, SOAP faults and empty responses are reported as errors instead of being treated as success.
+* `CrashReporter.NET.dll` is always strong-name signed with the key committed in this repository (public key token `dee93ec6287efbf0`). This identity differs from the upstream `CrashReporter.NET.Official` package, which was signed with RBSoft's private key. Versions 2.0.0 and 2.0.1 of `d3sync.CrashReporter.NET` were not signed; strong-named applications need 2.1.0 or later.
+* Reports saved by 2.0.x in `%TEMP%\CrashReporterNET\` (not in an application folder) are not retried.
+
### Upgrading from 1.x
Version 2.0 is a breaking release:
@@ -128,7 +142,8 @@ public partial class App : Application
{
Silent = true
};
- _reportCrash.RetryFailedReports();
+ // Retry reports that could not be sent earlier, in the background so startup is not blocked.
+ _ = _reportCrash.RetryFailedReportsAsync();
}
private void TaskSchedulerOnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs unobservedTaskExceptionEventArgs)