{"record":{"id":"191172a1c2b93538","repo":"JamesNK/Newtonsoft.Json","slug":"could-not-create-getter-for-0","errorCode":null,"errorMessage":"Could not create getter for {0}.","messagePattern":"Could not create getter for (.+?)\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/Utilities/ReflectionDelegateFactory.cs","lineNumber":59,"sourceCode":"        public Func<T, object?> CreateGet<T>(MemberInfo memberInfo)\n        {\n            if (memberInfo is PropertyInfo propertyInfo)\n            {\n                // https://github.com/dotnet/corefx/issues/26053\n                if (propertyInfo.PropertyType.IsByRef)\n                {\n                    throw new InvalidOperationException(\"Could not create getter for {0}. ByRef return values are not supported.\".FormatWith(CultureInfo.InvariantCulture, propertyInfo));\n                }\n\n                return CreateGet<T>(propertyInfo);\n            }\n\n            if (memberInfo is FieldInfo fieldInfo)\n            {\n                return CreateGet<T>(fieldInfo);\n            }\n\n            throw new Exception(\"Could not create getter for {0}.\".FormatWith(CultureInfo.InvariantCulture, memberInfo));\n        }\n\n        [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]\n        public Action<T, object?> CreateSet<T>(MemberInfo memberInfo)\n        {\n            if (memberInfo is PropertyInfo propertyInfo)\n            {\n                return CreateSet<T>(propertyInfo);\n            }\n\n            if (memberInfo is FieldInfo fieldInfo)\n            {\n                return CreateSet<T>(fieldInfo);\n            }\n\n            throw new Exception(\"Could not create setter for {0}.\".FormatWith(CultureInfo.InvariantCulture, memberInfo));\n        }\n","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/Utilities/ReflectionDelegateFactory.cs#L41-L77","documentation":"Thrown by ReflectionDelegateFactory.CreateGet(MemberInfo) when the supplied MemberInfo is neither a PropertyInfo nor a FieldInfo. The generic CreateGet only knows how to build value getters for fields and properties; any other member kind (method, event, constructor, nested type) falls through to this exception. It signals that an unexpected member type was fed into the getter pipeline.","triggerScenarios":"Passing a MethodInfo, EventInfo, ConstructorInfo, or TypeInfo into CreateGet. Internally this can occur if a custom contract resolver or member-walking utility mistakenly treats a non-field/non-property member as a value source.","commonSituations":"Custom IContractResolver implementations, extension methods that iterate MemberInfo collections, or mismatches after upgrading Json.NET where member resolution logic changed.","solutions":["Ensure only FieldInfo or PropertyInfo is passed to CreateGet — filter the member set beforehand.","For methods, use CreateMethodCall instead.","Audit custom contract resolvers / reflection helpers for the member kinds they hand to the delegate factory."],"exampleFix":"// before\nvar getter = factory.CreateGet<object>(someMethodInfo);\n\n// after\nif (member is PropertyInfo p) getter = factory.CreateGet<object>(p);\nelse if (member is FieldInfo f)  getter = factory.CreateGet<object>(f);\nelse throw new InvalidOperationException($\"Unsupported member: {member}\");","handlingStrategy":"type-guard","validationCode":"if (member is not PropertyInfo and not FieldInfo) throw new InvalidOperationException($\"Cannot get {member.MemberType}\");\nvar getter = factory.CreateGet<object>(member);","typeGuard":"static bool IsGettableMember(MemberInfo m) => m is PropertyInfo or FieldInfo;","tryCatchPattern":null,"preventionTips":["Filter MemberInfo collections to PropertyInfo/FieldInfo before invoking the getter factory.","Use GetProperties()/GetFields() instead of the broad GetMembers().","In custom contract resolvers, guard member kinds before delegating to the factory."],"tags":["reflection","getter","member","type-mismatch"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}