{"record":{"id":"3fa6b048f241b522","repo":"pardeike/Harmony","slug":"member-must-be-of-type-eventinfo-fieldinfo-methodinfo-or","errorCode":null,"errorMessage":"Member must be of type EventInfo, FieldInfo, MethodInfo, or PropertyInfo","messagePattern":"Member must be of type EventInfo, FieldInfo, MethodInfo, or PropertyInfo","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Harmony/Tools/AccessTools.cs","lineNumber":912,"sourceCode":"\t\t\t\tFileLog.Debug(\"AccessTools.GetPropertyNames: instance is null\");\r\n\t\t\t\treturn [];\r\n\t\t\t}\r\n\t\t\treturn GetPropertyNames(instance.GetType());\r\n\t\t}\r\n\r\n\t\t/// <summary>Gets the type of any class member of</summary>\r\n\t\t/// <param name=\"member\">A member</param>\r\n\t\t/// <returns>The class/type of this member</returns>\r\n\t\t///\r\n\t\tpublic static Type GetUnderlyingType(this MemberInfo member)\r\n\t\t{\r\n\t\t\treturn member.MemberType switch\r\n\t\t\t{\r\n\t\t\t\tMemberTypes.Event => ((EventInfo)member).EventHandlerType,\r\n\t\t\t\tMemberTypes.Field => ((FieldInfo)member).FieldType,\r\n\t\t\t\tMemberTypes.Method => ((MethodInfo)member).ReturnType,\r\n\t\t\t\tMemberTypes.Property => ((PropertyInfo)member).PropertyType,\r\n\t\t\t\t_ => throw new ArgumentException(\"Member must be of type EventInfo, FieldInfo, MethodInfo, or PropertyInfo\"),\r\n\t\t\t};\r\n\t\t}\r\n\r\n\t\t/// <summary>Returns a <see cref=\"MethodInfo\"/> by searching for module-id and token</summary>\r\n\t\t/// <param name=\"moduleGUID\">The module of the method</param>\r\n\t\t/// <param name=\"token\">The token of the method</param>\r\n\t\t/// <returns></returns>\r\n\t\tpublic static MethodInfo GetMethodByModuleAndToken(string moduleGUID, int token)\r\n\t\t{\r\n#if NET5_0_OR_GREATER\r\n\t\t\tModule module = null;\r\n\t\t\tvar assemblies = AppDomain.CurrentDomain.GetAssemblies();\r\n\t\t\tvar moduleVersionGUID = new Guid(moduleGUID);\r\n\t\t\tParallel.ForEach(assemblies, (assembly) =>\r\n\t\t\t{\r\n\t\t\t\tvar allModules = assembly.GetModules();\r\n\t\t\t\tfor (var i = 0; i < allModules.Length; i++)\r\n\t\t\t\t\tif (allModules[i].ModuleVersionId == moduleVersionGUID)\r","sourceCodeStart":894,"sourceCodeEnd":930,"githubUrl":"https://github.com/pardeike/Harmony/blob/e7872dc17008bc0ca2b3de1f53fd4120dbd7a17c/Harmony/Tools/AccessTools.cs#L894-L930","documentation":"AccessTools.GetUnderlyingType throws this ArgumentException when the MemberInfo passed to it is not an EventInfo, FieldInfo, MethodInfo, or PropertyInfo (e.g. it is a Type, ConstructorInfo, or nested type). The switch over MemberTypes has no matching case for such members, so Harmony throws to signal an unusable input. The method only computes 'the type of data a member holds/returns', which does not exist for other member kinds.","triggerScenarios":"Calling AccessTools.GetUnderlyingType with a ConstructorInfo (e.g. obtained from AccessTools.Constructor), a Type object, a nested type, or any MemberInfo whose MemberType is not Event/Field/Method/Property.","commonSituations":"Passing the result of AccessTools.Constructor or AccessTools.TypeByName into GetUnderlyingType, or generically processing MemberInfo collections that include constructors and nested types.","solutions":["Verify member.MemberType is one of MemberTypes.Event/Field/Method/Property before calling GetUnderlyingType","Filter collections with .Where(m => m is not ConstructorInfo and not Type) before processing","Use member.GetType()-specific APIs (e.g. ConstructorInfo has no return type) for other member kinds"],"exampleFix":"// before\nvar t = AccessTools.GetUnderlyingType(AccessTools.Constructor(typeof(Foo)));\n// after\nMemberInfo mi = AccessTools.Method(typeof(Foo), \"Bar\");\nvar t = mi is ConstructorInfo ? null : AccessTools.GetUnderlyingType(mi);","handlingStrategy":"type-guard","validationCode":"if (member is not (EventInfo or FieldInfo or MethodInfo or PropertyInfo)) throw new ArgumentException($\"Unsupported member: {member?.GetType().Name}\");","typeGuard":"bool SupportsGetUnderlyingType(MemberInfo m) => m is EventInfo or FieldInfo or MethodInfo or PropertyInfo;","tryCatchPattern":null,"preventionTips":["Filter MemberInfo collections before calling GetUnderlyingType","Never pass ConstructorInfo or nested Types into it","Assert member.MemberType with a debug check in shared patch helpers"],"tags":["reflection","harmony","argument","memberinfo"],"backgroundTag":"invalid-argument-value","analyzedSha":"e7872dc17008bc0ca2b3de1f53fd4120dbd7a17c","analyzedAt":"2026-09-15T22:47:11.550Z","contentChangedAt":"2026-09-15T22:47:11.550Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}