{"record":{"id":"0aa9a874a418d2b4","repo":"JamesNK/Newtonsoft.Json","slug":"memberinfo-must-be-of-type-fieldinfo-propertyinfo","errorCode":null,"errorMessage":"MemberInfo must be of type FieldInfo, PropertyInfo, EventInfo or MethodInfo","messagePattern":"MemberInfo must be of type FieldInfo, PropertyInfo, EventInfo or MethodInfo","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs","lineNumber":486,"sourceCode":"        /// </summary>\n        /// <param name=\"member\">The member.</param>\n        /// <returns>The underlying type of the member.</returns>\n        public static Type GetMemberUnderlyingType(MemberInfo member)\n        {\n            ValidationUtils.ArgumentNotNull(member, nameof(member));\n\n            switch (member.MemberType())\n            {\n                case MemberTypes.Field:\n                    return ((FieldInfo)member).FieldType;\n                case MemberTypes.Property:\n                    return ((PropertyInfo)member).PropertyType;\n                case MemberTypes.Event:\n                    return ((EventInfo)member).EventHandlerType!;\n                case MemberTypes.Method:\n                    return ((MethodInfo)member).ReturnType;\n                default:\n                    throw new ArgumentException(\"MemberInfo must be of type FieldInfo, PropertyInfo, EventInfo or MethodInfo\", nameof(member));\n            }\n        }\n\n        public static bool IsByRefLikeType(Type type)\n        {\n            if (!type.IsValueType())\n            {\n                return false;\n            }\n\n            // IsByRefLike flag on type is not available in netstandard2.0\n            Attribute[] attributes = GetAttributes(type, null, false);\n            for (int i = 0; i < attributes.Length; i++)\n            {\n                if (string.Equals(attributes[i].GetType().FullName, \"System.Runtime.CompilerServices.IsByRefLikeAttribute\", StringComparison.Ordinal))\n                {\n                    return true;\n                }","sourceCodeStart":468,"sourceCodeEnd":504,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs#L468-L504","documentation":"Thrown by ReflectionUtils.GetMemberUnderlyingType's default case when a MemberInfo is not a Field, Property, Event, or Method. Only those four member kinds carry a meaningful underlying type that this utility knows how to extract; constructors, nested types, and TypeInfo fall through to this exception.","triggerScenarios":"Calling GetMemberUnderlyingType with a ConstructorInfo, a nested TypeInfo, or any member whose MemberType is not Field/Property/Event/Method.","commonSituations":"Custom code that walks arbitrary MemberInfo collections (e.g. GetMembers()) without filtering by MemberType, or reflection helpers that assume all members are fields/properties.","solutions":["Filter to Field/Property/Event/Method before calling GetMemberUnderlyingType.","Handle other member kinds (nested types, constructors) explicitly in your code.","Prefer GetFields()/GetProperties() over the broad GetMembers() when iterating."],"exampleFix":"// before\nforeach (MemberInfo m in type.GetMembers())\n    types.Add(ReflectionUtils.GetMemberUnderlyingType(m));\n\n// after\nforeach (MemberInfo m in type.GetMembers())\n    if (m is FieldInfo or PropertyInfo or EventInfo or MethodInfo)\n        types.Add(ReflectionUtils.GetMemberUnderlyingType(m));","handlingStrategy":"type-guard","validationCode":"if (member is not FieldInfo and not PropertyInfo and not EventInfo and not MethodInfo)\n    throw new ArgumentException($\"Unsupported member type: {member.MemberType}\");","typeGuard":"static bool HasUnderlyingType(MemberInfo m) => m is FieldInfo or PropertyInfo or EventInfo or MethodInfo;","tryCatchPattern":null,"preventionTips":["Filter members to Field/Property/Event/Method before calling GetMemberUnderlyingType.","Prefer GetFields()/GetProperties()/GetMethods()/GetEvents() over GetMembers().","Handle nested types and constructors explicitly in your code."],"tags":["reflection","member","type","member-type"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}