peass-ng/PEASS-ng · error · InvalidEnumArgumentException
value
Error message
value
What it means
CheckHasValue<T> validates that an enum argument holds a value defined by the enum (or, for flags enums, any combination of defined bits). On failure it throws InvalidEnumArgumentException naming the argument (default "value"), i.e. the message 'value' is the parameter name of the offending argument, not a description.
Source
Thrown at winPEAS/winPEASexe/winPEAS/TaskScheduler/EnumUtil.cs:32
throw new ArgumentException($"Type '{typeof(T).FullName}' doesn't have the 'Flags' attribute");
}
public static bool IsFlags<T>() => Attribute.IsDefined(typeof(T), typeof(FlagsAttribute));
public static void CheckHasValue<T>(T value, string argName = null)
{
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;
}View on GitHub (pinned to 53fb989abc)
Solutions
- Pass only values that are defined members of the enum type, or valid bitwise combinations for flags enums.
- Cast to the enum type rather than passing raw ints so invalid values are caught earlier.
- Validate with Enum.IsDefined (or a mask check for flags) before calling APIs that use CheckHasValue.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at winPEAS/winPEASexe/winPEAS/TaskScheduler/EnumUtil.cs:32 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/431bfa7186d12376.
Report an issue: GitHub.