Skip to content

Commit 9b184cd

Browse files
committed
Fixed an issue where message object was disposed before message was sent.
1 parent 4bbbe46 commit 9b184cd

2 files changed

Lines changed: 19 additions & 19 deletions

File tree

CrashReporter.NET/HelperMethods.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ private static string HKLM_GetString(string key, string value)
4444
try
4545
{
4646
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(key);
47-
return registryKey?.GetValue(value).ToString() ?? String.Empty;
47+
return registryKey?.GetValue(value)?.ToString() ?? String.Empty;
4848
}
4949
catch
5050
{

CrashReporter.NET/ReportCrash.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -339,33 +339,33 @@ private void SendEmail(bool includeScreenshot, SendCompletedEventHandler smtpCli
339339
EnableSsl = EnableSSL,
340340
DeliveryMethod = SmtpDeliveryMethod.Network,
341341
UseDefaultCredentials = false,
342-
Credentials = new NetworkCredential(UserName, Password),
342+
Credentials = new NetworkCredential(UserName, Password)
343343
};
344+
345+
var message = new MailMessage(new MailAddress(FromEmail), new MailAddress(ToEmail))
346+
{IsBodyHtml = true, Subject = subject, Body = CreateHtmlReport(userMessage)};
344347

345-
using (var message = new MailMessage(new MailAddress(FromEmail), new MailAddress(ToEmail)) {IsBodyHtml = true, Subject = subject, Body = CreateHtmlReport(userMessage)})
348+
if (ScreenShotBinary?.Length > 0 && includeScreenshot)
346349
{
347-
if (ScreenShotBinary?.Length > 0 && includeScreenshot)
348-
{
349-
message.Attachments.Add(new Attachment(new MemoryStream(ScreenShotBinary), "Screenshot.png", "image/png"));
350-
}
350+
message.Attachments.Add(new Attachment(new MemoryStream(ScreenShotBinary), "Screenshot.png", "image/png"));
351+
}
351352

352-
if (smtpClientSendCompleted != null)
353+
if (smtpClientSendCompleted != null)
354+
{
355+
try
353356
{
354-
try
355-
{
356-
smtpClient.SendCompleted += smtpClientSendCompleted;
357-
smtpClient.SendAsync(message, "Crash Report");
358-
}
359-
catch (SmtpException smtpException)
360-
{
361-
smtpClientSendCompleted(this, new System.ComponentModel.AsyncCompletedEventArgs(smtpException, true, null));
362-
}
357+
smtpClient.SendCompleted += smtpClientSendCompleted;
358+
smtpClient.SendAsync(message, "Crash Report");
363359
}
364-
else
360+
catch (SmtpException smtpException)
365361
{
366-
smtpClient.Send(message);
362+
smtpClientSendCompleted(this, new System.ComponentModel.AsyncCompletedEventArgs(smtpException, true, null));
367363
}
368364
}
365+
else
366+
{
367+
smtpClient.Send(message);
368+
}
369369
}
370370

371371
#endregion

0 commit comments

Comments
 (0)