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

  1. Check member.MemberType before calling IsStatic and handle unsupported kinds yourself.
  2. For unsupported kinds, fall back to manual inspection (e.g. 'IsStatic'-style property of the concrete info type).
  3. 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

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


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)