mgth/LittleBigMouse · error · FormatException
' ' is not a MAC address: expected twelve hexadecimal…
Error message
'${value}' is not a MAC address: expected twelve hexadecimal digits, optionally grouped by ':', '-' or '.'. What it means
ParseMacAddress strips separators (':', '-', '.') and whitespace from the input, then copies hex digits into a stack buffer of 2*MacLength characters. It throws NotAMacAddress(macAddress) — with this message — when it encounters either a full buffer followed by another non-separator character, or a character that is not a hex digit. This is the too-many/invalid-character branch at line 30.
Solutions
- Correct the MAC string to contain exactly 12 hex digits (0-9a-fA-F), optionally grouped by ':', '-' or '.', e.g. "AA:BB:CC:DD:EE:FF".
- Strip any label or trailing text before passing the value: pass only the address itself, not a whole settings line.
- Validate in config with a regex ^[0-9A-Fa-f]{2}([:-.]?[0-9A-Fa-f]{2}){5}$ before invoking the API.
- Verify you are not passing an IPv4/IP-based identifier where a MAC is required.
Example fix
// before
var packet = WakeOnLan.CreateMagicPacket("AA:BB:CC:DD:EE:GG"); // throws
// after
var packet = WakeOnLan.CreateMagicPacket("AA:BB:CC:DD:EE:FF"); // valid hex Defensive patterns
Strategy: validation
Validate before calling
static bool LooksLikeMac(string? mac) =>
!string.IsNullOrWhiteSpace(mac) &&
System.Text.RegularExpressions.Regex.IsMatch(mac, "^[0-9A-Fa-f]{2}([:-. ]?[0-9A-Fa-f]{2}){5}$"); Type guard
bool IsMacAddress(string? value) =>
!string.IsNullOrWhiteSpace(value) &&
value.Where(c => c != ':' && c != '-' && c != '.' && !char.IsWhiteSpace(c)).Count() == 12 &&
value.Where(c => c != ':' && c != '-' && c != '.' && !char.IsWhiteSpace(c)).All(Uri.IsHexDigit); Try / catch
try { var packet = WakeOnLan.CreateMagicPacket(mac); }
catch (FormatException e) when (e.Message.Contains("not a MAC address")) {
log.LogError("Invalid WOL target MAC '{Mac}'", mac);
ui.ShowFieldError(nameof(mac), "Expected 12 hex digits, optionally grouped by :, - or .");
} Prevention
- Validate MAC fields with a regex at config-load time, before any WOL call.
- Reject inputs with 13+ hex-digit groups or non-hex characters early with a friendly UI message.
- Copy MACs exactly as shown on the device screen; strip labels and surrounding text.
- Normalize once (remove separators) and store the canonical 12-digit form.
When it happens
Trigger: Calling ParseMacAddress (or CreateMagicPacket) with a string containing 12+ hex digits plus an invalid 13th+ character, or any non-hex character (e.g. 'G', '_') in the middle, e.g. "AA:BB:CC:DD:EE:GG" or "AA-BB-CC-DD-EE-FF-01".
Common situations: User typo in the Wake-on-LAN target MAC in config; pasting a MAC with a trailing label ('MAC: AA:BB...'); using an IPv4 address or UUID instead of a MAC; copy errors from the TV/device settings screen.
Understand the failure class
Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.
Related errors
- Enter a valid projector IPv4 address.
- A Wi-Fi MAC address is required for VIDAA authentication.
- The network device does not advertise VIDAA remote control.
- Invalid VIDAA remote key.
- Enter a VIDAA picture-setting menu ID between 1 and 999.
AI-assisted analysis of mgth/LittleBigMouse@7a42f01d47 (2026-09-16).
Data as JSON: /api/errors/73ae6c4464416819.
Report an issue: GitHub.
Appendix: source
Thrown at LittleBigMouse.Plugins/LittleBigMouse.Plugin.Vcp/Networking/WakeOnLan.cs:30
/// <summary>Length of every magic packet: 6 synchronisation bytes + 16 copies of the MAC.</summary>
public const int MagicPacketLength = MacLength + 16 * MacLength;
/// <summary>
/// Reads the six address bytes from the usual notations: "aa:bb:cc:dd:ee:ff",
/// "AA-BB-CC-DD-EE-FF", "aabb.ccdd.eeff" or twelve bare hexadecimal digits.
/// </summary>
/// <exception cref="FormatException">The value is not twelve hexadecimal digits.</exception>
public static byte[] ParseMacAddress(string macAddress)
{
ArgumentNullException.ThrowIfNull(macAddress);
Span<char> digits = stackalloc char[2 * MacLength];
var count = 0;
foreach (var character in macAddress)
{
if (character is ':' or '-' or '.' || char.IsWhiteSpace(character)) continue;
if (count == digits.Length || !Uri.IsHexDigit(character)) throw NotAMacAddress(macAddress);
digits[count++] = character;
}
if (count != digits.Length) throw NotAMacAddress(macAddress);
return Convert.FromHexString(digits);
}
/// <summary>Builds the magic packet waking <paramref name="macAddress"/>.</summary>
public static byte[] CreateMagicPacket(string macAddress)
{
var mac = ParseMacAddress(macAddress);
var packet = new byte[MagicPacketLength];
Array.Fill(packet, (byte)0xff, 0, MacLength);
for (var offset = MacLength; offset < packet.Length; offset += MacLength) mac.CopyTo(packet, offset);
return packet;
}
View on GitHub (pinned to 7a42f01d47)