pardeike/Harmony · error · ArgumentException
Unknown member type
Error message
Unknown member type: {member.MemberType} What it means
AccessTools.IsStatic(MemberInfo) throws ArgumentException('Unknown member type') when it receives a MemberInfo whose MemberType is none of Constructor, Method, Event, Field, Property, TypeInfo, or NestedType. Harmony has no staticness rule for that member kind, so it refuses to guess.
Solutions
- Check member.MemberType before calling IsStatic and handle unsupported kinds yourself.
- For unsupported kinds, fall back to manual inspection (e.g. 'IsStatic'-style property of the concrete info type).
- Upgrade Harmony if a new MemberType from a newer runtime is the cause.
Example fix
// before
var isStatic = AccessTools.IsStatic(anyMember);
// after
var isStatic = anyMember.MemberType is MemberTypes.Method or MemberTypes.Field or MemberTypes.Property or MemberTypes.Event or MemberTypes.Constructor or MemberTypes.TypeInfo or MemberTypes.NestedType
? AccessTools.IsStatic(anyMember)
: false; Defensive patterns
Strategy: type-guard
Validate before calling
switch (member) { case MethodBase: case FieldInfo: case PropertyInfo: case EventInfo: case Type: break; default: return false; } Type guard
bool IsSupportedMember(MemberInfo m) => m is MethodBase or FieldInfo or PropertyInfo or EventInfo or Type;
Try / catch
try { var s = AccessTools.IsStatic(member); }
catch (ArgumentException) { /* unsupported MemberType; handle manually */ } Prevention
- Filter MemberInfo collections to supported kinds before calling IsStatic.
- Handle MemberTypes explicitly in generic reflection code.
- Keep Harmony updated for new runtime member kinds.
When it happens
Trigger: Calling AccessTools.IsStatic(member) with a MemberInfo of an unhandled kind - practically this means new/obscure MemberTypes values (e.g. synthetized members) or a wrongly constructed MemberInfo.
Common situations: Writing generic reflection code that passes arbitrary MemberInfo (e.g. from member.MemberType filtering mistakes) into IsStatic; future .NET runtimes introducing member kinds Harmony does not yet handle.
Related errors
- The type must declare an empty constructor (the constructor…
- Unsupported inline signature parameter type
- Unsupported callsite element
- Value cannot be null. (Parameter 'fromMethod')
- Value cannot be null. (Parameter 'method')
AI-assisted analysis of pardeike/Harmony@e7872dc170 (2026-09-15).
Data as JSON: /api/errors/a1e7e52a71ee4181.
Report an issue: GitHub.
Appendix: source
Thrown at Harmony/Tools/AccessTools.cs:2356
#pragma warning disable IDE0060
public static bool IsOfNullableType<T>(T instance) => Nullable.GetUnderlyingType(typeof(T)) is not null;
/// <summary>Tests whether a type or member is static, as defined in C#</summary>
/// <param name="member">The type or member</param>
/// <returns>True if the type or member is static</returns>
///
public static bool IsStatic(MemberInfo member)
{
if (member is null)
throw new ArgumentNullException(nameof(member));
return member.MemberType switch
{
MemberTypes.Constructor or MemberTypes.Method => ((MethodBase)member).IsStatic,
MemberTypes.Event => IsStatic((EventInfo)member),
MemberTypes.Field => ((FieldInfo)member).IsStatic,
MemberTypes.Property => IsStatic((PropertyInfo)member),
MemberTypes.TypeInfo or MemberTypes.NestedType => IsStatic((Type)member),
_ => throw new ArgumentException($"Unknown member type: {member.MemberType}"),
};
}
/// <summary>Tests whether a type is static, as defined in C#</summary>
/// <param name="type">The type</param>
/// <returns>True if the type is static</returns>
///
[EditorBrowsable(EditorBrowsableState.Never)]
public static bool IsStatic(Type type)
{
if (type is null)
return false;
return type.IsAbstract && type.IsSealed;
}
/// <summary>Tests whether a property is static, as defined in C#</summary>
/// <param name="propertyInfo">The property</param>
/// <returns>True if the property is static</returns>
View on GitHub (pinned to e7872dc170)