jstedfast/MailKit · error · ArgumentNullException
data
Error message
data
What it means
MailKit's WinRT-based KeyedHashAlgorithm wrapper (used for CRAM-MD5/NTLM on UWP) throws ArgumentNullException with parameter name "data" when ComputeHash is called with a null buffer. The buffer must be a real byte array because it is converted into an IBuffer via CryptographicBuffer.CreateFromByteArray before hashing.
Solutions
- Ensure the input byte array is non-null before calling ComputeHash (e.g., use ?? Array.Empty<byte>() if empty input is legal for your protocol).
- Check that the code producing the buffer (stream read, challenge decode) succeeded and did not return null.
- Note this is a null check, not a disposed-check — if you also see ObjectDisposedException, check disposal separately.
Example fix
// before byte[] hmac = hasher.ComputeHash(challengeBytes); // challengeBytes may be null // after byte[] hmac = hasher.ComputeHash(challengeBytes ?? Array.Empty<byte>());
Defensive patterns
Strategy: validation
Validate before calling
if (buffer == null) throw new InvalidOperationException("challenge bytes missing");
byte[] hash = hasher.ComputeHash(buffer); Type guard
static bool HasData(byte[] b) => b != null && b.Length > 0;
Try / catch
try {
var hash = hasher.ComputeHash(buffer);
} catch (ArgumentNullException) {
// null input: regenerate the buffer or abort the auth exchange
} Prevention
- Ensure stream reads and challenge decoders never return null (use Array.Empty as sentinel).
- Check return values of any byte-array-producing helper before hashing.
- Dispose keyed-hash contexts promptly so disposal-state errors don't get conflated with null inputs.
When it happens
Trigger: Calling ComputeHash((byte[]) null) on a disposed-or-valid keyed hash context — the null check fires before any use of the underlying hmac object.
Common situations: Hashing data read from a stream or SASL challenge where the byte-array conversion step returned null; passing an uninitialized field; a custom SASL mechanism that passes the raw (null) challenge through.
Related errors
AI-assisted analysis of jstedfast/MailKit@9d3859a785 (2026-09-15).
Data as JSON: /api/errors/99eb7b53771fbd9a.
Report an issue: GitHub.
Appendix: source
Thrown at MailKit/Security/KeyedHashAlgorithm.cs:75
/// <summary>
/// Computes the hash code for the buffer.
/// </summary>
/// <remarks>
/// Computes the hash code for the buffer.
/// </remarks>
/// <returns>The computed hash code.</returns>
/// <param name="buffer">The buffer.</param>
/// <exception cref="System.ArgumentNullException">
/// <paramref name="buffer"/> is <c>null</c>.
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The keyed hash algorithm context has been disposed.
/// </exception>
public byte[] ComputeHash (byte[] buffer)
{
if (buffer == null)
throw new ArgumentNullException ("data");
hmac.Append (CryptographicBuffer.CreateFromByteArray (buffer));
var value = hmac.GetValueAndReset ();
byte[] hash;
CryptographicBuffer.CopyToByteArray (value, out hash);
return hash;
}
/// <summary>
/// Releases all resource used by the <see cref="MailKit.Security.KeyedHashAlgorithm"/> object.
/// </summary>
/// <remarks>Call <see cref="Dispose()"/> when you are finished using the <see cref="MailKit.Security.KeyedHashAlgorithm"/>. The
/// <see cref="Dispose()"/> method leaves the <see cref="MailKit.Security.KeyedHashAlgorithm"/> in an unusable state. After calling
/// <see cref="Dispose()"/>, you must release all references to the <see cref="MailKit.Security.KeyedHashAlgorithm"/> so the
/// garbage collector can reclaim the memory that the <see cref="MailKit.Security.KeyedHashAlgorithm"/> was occupying.</remarks>
public void Dispose ()View on GitHub (pinned to 9d3859a785)