{"record":{"id":"ae4f2bad711d7a8e","repo":"JamesNK/Newtonsoft.Json","slug":"could-not-create-setter-for-0","errorCode":null,"errorMessage":"Could not create setter for {0}.","messagePattern":"Could not create setter for (.+?)\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/Utilities/ReflectionDelegateFactory.cs","lineNumber":75,"sourceCode":"            }\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\n        [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]\n        public abstract MethodCall<T, object?> CreateMethodCall<T>(MethodBase method);\n        [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]\n        public abstract ObjectConstructor<object> CreateParameterizedConstructor(MethodBase method);\n        [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]\n        public abstract Func<T> CreateDefaultConstructor<T>(\n            [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]\n            Type type);\n        [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]\n        public abstract Func<T, object?> CreateGet<T>(PropertyInfo propertyInfo);\n        [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]\n        public abstract Func<T, object?> CreateGet<T>(FieldInfo fieldInfo);\n        [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]\n        public abstract Action<T, object?> CreateSet<T>(FieldInfo fieldInfo);\n        [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]\n        public abstract Action<T, object?> CreateSet<T>(PropertyInfo propertyInfo);","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/Utilities/ReflectionDelegateFactory.cs#L57-L93","documentation":"Thrown by ReflectionDelegateFactory.CreateSet(MemberInfo) when the MemberInfo is neither a PropertyInfo nor a FieldInfo. The setter delegate pipeline only supports fields and properties; methods, events, and other member kinds have no value-assignment semantics in this factory.","triggerScenarios":"Passing a MethodInfo, EventInfo, or other MemberInfo into CreateSet. Can happen in custom contract resolvers that incorrectly route non-settable members as assignment targets.","commonSituations":"Custom contract resolvers that misclassify methods as settable, or reflection utilities that walk all members without filtering by kind.","solutions":["Ensure only FieldInfo or PropertyInfo is passed to CreateSet.","Filter the member set to settable kinds before invoking the factory.","Review custom member-resolution code that feeds the setter pipeline."],"exampleFix":"// before\nvar setter = factory.CreateSet<object>(anyMember);\n\n// after\nswitch (member)\n{\n    case PropertyInfo pi: setter = factory.CreateSet<object>(pi); break;\n    case FieldInfo fi:    setter = factory.CreateSet<object>(fi); break;\n    default: throw new InvalidOperationException($\"Cannot set {member.MemberType}\");\n}","handlingStrategy":"type-guard","validationCode":"if (member is not PropertyInfo and not FieldInfo) throw new InvalidOperationException($\"Cannot set {member.MemberType}\");\nvar setter = factory.CreateSet<object>(member);","typeGuard":"static bool IsSettableMember(MemberInfo m) => m is PropertyInfo or FieldInfo;","tryCatchPattern":null,"preventionTips":["Filter to PropertyInfo/FieldInfo before invoking the setter factory.","Use GetProperties()/GetFields() instead of GetMembers().","Audit custom contract resolvers for the member kinds they route to setters."],"tags":["reflection","setter","member","type-mismatch"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}