peass-ng/PEASS-ng · error · ArgumentException
The flag value is zero and has no bit position.
Error message
The flag value is zero and has no bit position.
What it means
BitPosition<T> computes the single set bit of a flags value; it throws InvalidEnumArgumentException (with the descriptive text about a zero value having no bit position) when the value is 0, because zero has no bit to locate. The at-fault input is a flags enum value of 0 passed to this extension.
Source
Thrown at winPEAS/winPEASexe/winPEAS/TaskScheduler/EnumUtil.cs:39
CheckIsEnum<T>();
if (IsFlags<T>())
{
var allFlags = 0L;
foreach (T flag in Enum.GetValues(typeof(T)))
allFlags |= Convert.ToInt64(flag);
if ((allFlags & Convert.ToInt64(value)) != 0L)
return;
}
else if (Enum.IsDefined(typeof(T), value))
return;
throw new InvalidEnumArgumentException(argName ?? "value", Convert.ToInt32(value), typeof(T));
}
public static byte BitPosition<T>(this T flags) where T : struct, IConvertible
{
CheckIsEnum<T>(true);
var flagValue = Convert.ToInt64(flags);
if (flagValue == 0) throw new ArgumentException("The flag value is zero and has no bit position.");
var r = Math.Log(flagValue, 2);
if (r % 1 > 0) throw new ArithmeticException("The flag value has more than a single bit set.");
return Convert.ToByte(r);
}
public static bool IsFlagSet<T>(this T flags, T flag) where T : struct, IConvertible
{
CheckIsEnum<T>(true);
var flagValue = Convert.ToInt64(flag);
return (Convert.ToInt64(flags) & flagValue) == flagValue;
}
public static bool IsValidFlagValue<T>(this T flags) where T : struct, IConvertible
{
CheckIsEnum<T>(true);
var found = 0L;
foreach (T flag in Enum.GetValues(typeof(T)))
{View on GitHub (pinned to 53fb989abc)
Solutions
- Check the value for 0 before calling BitPosition and handle the 'no bit set' case explicitly.
- Only call BitPosition on values known to have exactly one bit set.
- Wrap the call in try/catch for InvalidEnumArgumentException when arbitrary flags values may arrive.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at winPEAS/winPEASexe/winPEAS/TaskScheduler/EnumUtil.cs:39 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02).
Data as JSON: /api/errors/4f4daa740619e3ab.
Report an issue: GitHub.