From e40d971de0038b5d683cf8d65c89d59e2e3bc2c6 Mon Sep 17 00:00:00 2001 From: redlineo Date: Fri, 24 Jul 2026 10:26:29 +0300 Subject: [PATCH] Fix crash opening bulk sender window (rows null during InitializeComponent) Real stack trace from the operator's machine pinned it down: WinForms fires DataGridView.CellValueChanged as a side effect of DataGridViewColumn.HeaderText assignments inside InitializeComponent(), i.e. before PreviewForm's constructor has had a chance to run RunScan() and populate the `rows` field. UpdateSummaryLabel() then hit rows.Count(...) on a null source. Nothing to do with Outlook/COM at all - a pure WinForms initialization-order gotcha. Co-Authored-By: Claude Sonnet 5 --- .../BulkArchiveMailer.AddIn/UI/PreviewForm.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/outlook-bulk-sender/BulkArchiveMailer.AddIn/UI/PreviewForm.cs b/outlook-bulk-sender/BulkArchiveMailer.AddIn/UI/PreviewForm.cs index c4a8994..2032657 100644 --- a/outlook-bulk-sender/BulkArchiveMailer.AddIn/UI/PreviewForm.cs +++ b/outlook-bulk-sender/BulkArchiveMailer.AddIn/UI/PreviewForm.cs @@ -128,6 +128,17 @@ namespace BulkArchiveMailer.AddIn.UI private void UpdateSummaryLabel() { + if (rows == null) + { + // Can be invoked before RunScan() ever ran - most notably, + // WinForms fires DataGridView.CellValueChanged as a side + // effect of DataGridViewColumn.HeaderText assignments in + // InitializeComponent(), i.e. before the constructor (and + // therefore RunScan()) has had a chance to populate `rows`. + // Nothing to summarize yet in that case. + return; + } + var ready = rows.Count(r => r.Job.Status == SendStatus.Ready); var already = rows.Count(r => r.Job.Status == SendStatus.AlreadySent); var errors = rows.Count(r => r.Job.Status == SendStatus.Error);