jstedfast/MailKit · error · ArgumentException

The custom data must be 8 bytes.

Error message

The custom data must be 8 bytes.

What it means

The NtlmSingleHostData constructor throws ArgumentException when customData is not exactly 8 bytes. The NTLM Single_Host_Data format reserves a fixed 8-byte CustomData field, so any other length is invalid and rejected rather than truncated or padded.

Solutions

  1. Extract exactly 8 bytes for customData (e.g. buffer.AsSpan(start, 8).ToArray())
  2. Verify slicing offsets against the 48-byte Single_Host_Data layout
  3. Pad or truncate a foreign value to 8 bytes only if that matches your protocol contract

Example fix

// before
var customData = new byte[4];
new NtlmSingleHostData(customData, machineId);
// after
var customData = new byte[8];
Buffer.BlockCopy(blob, start, customData, 0, 8);
new NtlmSingleHostData(customData, machineId);
Defensive patterns

Strategy: type-guard

Validate before calling

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

Type guard

static bool Is8Bytes(byte[] d) => d is { Length: 8 };

Try / catch

try { var d = new NtlmSingleHostData(customData, machineId); }
catch (ArgumentException ex) when (ex.ParamName == "customData") { /* fix slicing */ }

Prevention

When it happens

Trigger: Calling new NtlmSingleHostData(customData, machineId) with customData.Length != 8 (e.g. a 4-byte or 16-byte slice from incorrect buffer math).

Common situations: Wrong slice boundaries when extracting customData from a 48-byte Single_Host_Data blob; confusing the 8-byte custom data with the 32-byte machine ID; copying a struct layout from a different NTLM variant.

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/d50c9883f5a0ea62. Report an issue: GitHub.

Appendix: source

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

		/// <param name="customData">The 8-byte platform-specific blob.</param>
		/// <param name="machineId">The 256-bit randomly generated machine id.</param>
		/// <exception cref="ArgumentNullException">
		/// <para><paramref name="customData"/> is <see langword="null" />.</para>
		/// <para>-or-</para>
		/// <para><paramref name="machineId"/> is <see langword="null" />.</para>
		/// </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>

View on GitHub (pinned to 9d3859a785)