{"record":{"id":"50738ab37f98cd73","repo":"JamesNK/Newtonsoft.Json","slug":"property-0-does-not-have-a-getter","errorCode":null,"errorMessage":"Property '{0}' does not have a getter.","messagePattern":"Property '(.+?)' does not have a getter\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/Utilities/DynamicReflectionDelegateFactory.cs","lineNumber":312,"sourceCode":"        }\n\n        [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]\n        public override Func<T, object?> CreateGet<T>(PropertyInfo propertyInfo)\n        {\n            DynamicMethod dynamicMethod = CreateDynamicMethod(\"Get\" + propertyInfo.Name, typeof(object), new[] { typeof(T) }, propertyInfo.DeclaringType!);\n            ILGenerator generator = dynamicMethod.GetILGenerator();\n\n            GenerateCreateGetPropertyIL(propertyInfo, generator);\n\n            return (Func<T, object?>)dynamicMethod.CreateDelegate(typeof(Func<T, object?>));\n        }\n\n        private void GenerateCreateGetPropertyIL(PropertyInfo propertyInfo, ILGenerator generator)\n        {\n            MethodInfo? getMethod = propertyInfo.GetGetMethod(true);\n            if (getMethod == null)\n            {\n                throw new ArgumentException(\"Property '{0}' does not have a getter.\".FormatWith(CultureInfo.InvariantCulture, propertyInfo.Name));\n            }\n\n            if (!getMethod.IsStatic)\n            {\n                generator.PushInstance(propertyInfo.DeclaringType!);\n            }\n\n            generator.CallMethod(getMethod);\n            generator.BoxIfNeeded(propertyInfo.PropertyType);\n            generator.Return();\n        }\n\n        [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]\n        public override Func<T, object?> CreateGet<T>(FieldInfo fieldInfo)\n        {\n            if (fieldInfo.IsLiteral)\n            {\n                object constantValue = fieldInfo.GetValue(null)!;","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/Utilities/DynamicReflectionDelegateFactory.cs#L294-L330","documentation":"GenerateCreateGetPropertyIL (DynamicReflectionDelegateFactory.cs:307-323) builds a compiled getter delegate for a PropertyInfo. It calls propertyInfo.GetGetMethod(true); if the property has no get accessor (write-only property), getMethod is null and it throws ArgumentException at DynamicReflectionDelegateFactory.cs:312. This factory is used on platforms where ReflectionEmit is available.","triggerScenarios":"The serializer's contract creation tries to build a getter for a write-only property (one with only a setter) on a platform using the DynamicReflectionDelegateFactory.","commonSituations":"Properties intentionally exposed as write-only (set; only); fluent-builder-style APIs; generated proxy types with asymmetric accessors.","solutions":["Add a getter to the property (even a private one, since GetGetMethod(true) retrieves non-public).","Mark the write-only property with [JsonIgnore] so the serializer skips it.","Use a custom IContractResolver/ContractResolver that excludes properties without a getter (CanRead == false).","Map the value through a different, readable member."],"exampleFix":"// before\npublic string Secret { set; } // write-only -> throws on serialize\n// after\n[JsonIgnore]\npublic string Secret { set; }","handlingStrategy":"validation","validationCode":"// Skip write-only properties when building a contract.\nforeach (var prop in type.GetProperties()) {\n    if (prop.GetGetMethod(true) == null) continue; // write-only\n    /* build getter */\n}","typeGuard":"static bool HasGetter(System.Reflection.PropertyInfo p) => p.GetGetMethod(true) != null;","tryCatchPattern":"try { serializer.Serialize(writer, value); } catch (ArgumentException ex) when (ex.Message.Contains(\"does not have a getter\")) { /* mark offending property [JsonIgnore] */ }","preventionTips":["Mark write-only properties with [JsonIgnore].","Use a contract resolver that excludes properties where !CanRead.","Add a getter (even private) to properties that must be serialized."],"tags":["reflection","serialization","property","newtonsoft-json"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}