jstedfast/MailKit · error · InvalidOperationException

No hash value computed.

Error message

No hash value computed.

What it means

HMACMD5.Hash throws InvalidOperationException("No hash value computed.") when hashValue is null, i.e. Hash is read before ComputeHash has ever been called. The Hash property only exposes a previously computed digest.

Solutions

  1. Call ComputeHash before reading Hash
  2. Cache the hash returned by ComputeHash instead of re-reading the property
  3. Catch InvalidOperationException and treat as 'digest not yet computed'

Example fix

// before
var hmac = new HMACMD5(key);
var digest = hmac.Hash; // throws
// after
var hmac = new HMACMD5(key);
var digest = hmac.ComputeHash(data);
Defensive patterns

Strategy: validation

Validate before calling

if (hmacHashNotComputed) throw new InvalidOperationException("call ComputeHash before reading Hash");

Type guard

bool HasDigest(HMACMD5 h) => h.Hash != null;

Try / catch

try { var d = hmac.Hash; } catch (InvalidOperationException) { d = hmac.ComputeHash(data); }

Prevention

When it happens

Trigger: Accessing hmac.Hash immediately after construction or after Key was reassigned (which resets state) without calling ComputeHash first.

Common situations: Debug/logging code reading .Hash speculatively; re-keying then assuming the old hash is still available.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of jstedfast/MailKit@9d3859a785 (2026-09-15). Data as JSON: /api/errors/0e0133e25cb86273. Report an issue: GitHub.

Appendix: source

Thrown at MailKit/Security/Ntlm/HMACMD5.cs:55

		readonly HMac hash = new HMac (new MD5Digest ());
		byte[] hashValue, key;
		bool disposed;

		public HMACMD5 (byte[] key)
		{
			Key = key;
		}

		~HMACMD5 ()
		{
			Dispose (false);
		}

		public byte[] Hash
		{
			get {
				if (hashValue == null)
					throw new InvalidOperationException ("No hash value computed.");

				return hashValue;
			}
		}

		public byte[] Key {
			get { return key; }
			set {
				if (value == null)
					throw new ArgumentNullException (nameof (value));

				if (key != null)
					Array.Clear (key, 0, key.Length);

				key = value;
				Initialize ();
			}
		}

View on GitHub (pinned to 9d3859a785)