netchx/netch · error · MessageException

The downloaded file has the wrong hash

Error message

The downloaded file has the wrong hash

What it means

Thrown by MainForm's update routine when the SHA-256 of the freshly downloaded update file does not equal the expected sha256 from UpdateChecker.GetLatestUpdateFileNameAndHash. The file is present but its content does not match the published hash, so the updater refuses to apply it.

Source

Thrown at Netch/Forms/MainForm.cs:473

                else
                    File.Delete(updateFileFullName);
            }

            if (!downloaded)
            {
                try
                {
                    await WebUtil.DownloadFileAsync(updateFileUrl, updateFileFullName, progress);
                }
                catch (Exception e1)
                {
                    Log.Warning(e1, "Download Update File Failed");
                    throw new MessageException($"Download Update File Failed: {e1.Message}");
                }

                var fileHash = await Utils.Utils.Sha256CheckSumAsync(updateFileFullName);
                if (fileHash != sha256)
                    throw new MessageException(i18N.Translate("The downloaded file has the wrong hash"));
            }

            await StopAsync();
            await Configuration.SaveAsync();

            // Update
            await Task.Run(updater.ApplyUpdate);

            // release mutex, exit
            Program.SingleInstance.Dispose();
            Process.Start(Global.NetchExecutable);
            Environment.Exit(0);
        }
        catch (MessageException exception)
        {
            NotifyTip(exception.Message, info: false);
        }
        catch (Exception exception)

View on GitHub (pinned to 9d99eb1c5a)

Solutions

  1. Delete data\<updateFileName> and retry the download to get a clean copy.
  2. Verify network path integrity (disable interfering proxy/VPN for the download).
  3. Compare the published sha256 in the release notes against what Utils.Utils.Sha256CheckSumAsync computes locally.
  4. If the published hash itself is wrong, wait for a corrected release or report it.
  5. Download the asset manually in a browser, hash it, and only place it in data\ if it matches.
Defensive patterns

Strategy: retry

Validate before calling

// If a partial file exists, recompute and only trust it when it matches.
if (File.Exists(updateFileFullName))
{
    if (await Utils.Utils.Sha256CheckSumAsync(updateFileFullName) != sha256)
        File.Delete(updateFileFullName); // discard corrupt/partial file
}

Try / catch

string fileHash;
do
{
    try { await WebUtil.DownloadFileAsync(updateFileUrl, updateFileFullName, progress); }
    catch (Exception e1) { throw new MessageException($"Download Update File Failed: {e1.Message}"); }
    fileHash = await Utils.Utils.Sha256CheckSumAsync(updateFileFullName);
    if (fileHash != sha256) File.Delete(updateFileFullName); // throw away the bad copy and retry
} while (fileHash != shaHash);

Prevention

When it happens

Trigger: Partial/corrupted download truncated by a dropped connection; a transparent proxy/MITM altered the bytes; the published hash in the release metadata is stale or wrong; the GitHub asset was republished under the same name with different content; disk write corruption.

Common situations: Connection dropped mid-download leaving a truncated file; CDN/cache served a stale or wrong artifact; user is behind a filtering proxy that rewrote the binary.

Related errors


AI-assisted analysis of netchx/netch@9d99eb1c5a (2026-08-13). Data as JSON: /api/errors/5cfd3202a71d512a. Report an issue: GitHub.