jstedfast/MailKit · error · ArgumentException

The machine id must be 32 bytes.

Error message

The machine id must be 32 bytes.

What it means

The NtlmSingleHostData constructor throws ArgumentException when machineId is not exactly 32 bytes. The MachineID field in NTLM Single_Host_Data is a fixed 32-byte value, so any other length is rejected. This keeps the encoded structure a well-formed 48 bytes.

Solutions

  1. Pass exactly 32 bytes for machineId (e.g. HMAC-SHA256 output or the decoded 32-byte field)
  2. Check the argument order: customData (8 bytes) first, machineId (32 bytes) second
  3. Verify offsets when slicing a 48-byte Single_Host_Data blob

Example fix

// before
var machineId = sha1.ComputeHash(data); // 20 bytes
new NtlmSingleHostData(customData, machineId);
// after
var machineId = hmacSha256.ComputeHash(data); // 32 bytes
new NtlmSingleHostData(customData, machineId);
Defensive patterns

Strategy: type-guard

Validate before calling

if (machineId is null || machineId.Length != 32)
    throw new ArgumentException("machineId must be exactly 32 bytes");

Type guard

static bool Is32Bytes(byte[] m) => m is { Length: 32 };

Try / catch

try { var d = new NtlmSingleHostData(customData, machineId); }
catch (ArgumentException ex) when (ex.ParamName == "machineId") { /* use a proper 32-byte hash */ }

Prevention

When it happens

Trigger: Calling new NtlmSingleHostData(customData, machineId) with machineId.Length != 32 — e.g. passing a SHA-1 hash (20 bytes), a GUID (16 bytes), or an over-long buffer slice.

Common situations: Using a different hash algorithm output as the machine ID; swapping the 8-byte customData and 32-byte machineId arguments; slicing the blob with wrong offsets so the tail got merged into the machine ID.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at MailKit/Security/Ntlm/NtlmSingleHostData.cs:85

		/// </exception>
		/// <exception cref="ArgumentException">
		/// <para><paramref name="customData"/> is not 8 bytes.</para>
		/// <para>-or-</para>
		/// <para><paramref name="machineId"/> is not 32 bytes.</para>
		/// </exception>
		public NtlmSingleHostData (byte[] customData, byte[] machineId)
		{
			if (customData == null)
				throw new ArgumentNullException (nameof (customData));

			if (customData.Length != 8)
				throw new ArgumentException ("The custom data must be 8 bytes.", nameof (customData));

			if (machineId == null)
				throw new ArgumentNullException (nameof (machineId));

			if (machineId.Length != 32)
				throw new ArgumentException ("The machine id must be 32 bytes.", nameof (machineId));

			CustomData = customData;
			MachineId = machineId;
			Size = 48;
		}

		/// <summary>
		/// Get or set an 8-byte platform-specific blob.
		/// </summary>
		/// <remarks>
		/// Gets or sets an 8-byte platform-specific blob.
		/// </remarks>
		public byte[] CustomData {
			get; private set;
		}

		/// <summary>
		/// Get the 256-bit randomly generated machine ID.

View on GitHub (pinned to 9d3859a785)