{"record":{"id":"ab9d407c9899f087","repo":"bchavez/Bogus","slug":"the-specified-property-property-name-does-not","errorCode":null,"errorMessage":"The specified property '{property.Name}' does not have a setter method.","messagePattern":"The specified property '(.+?)' does not have a setter method\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Source/Bogus/Extensions/ExtensionsForPropertyInfo.cs","lineNumber":16,"sourceCode":"using System;\nusing System.Reflection;\n\nnamespace Bogus.Extensions;\n\npublic static class ExtensionsForPropertyInfo\n{\n   private static readonly MethodInfo GenericSetterCreationMethod = \n      typeof(ExtensionsForPropertyInfo).GetMethod(nameof(CreateSetterGeneric), BindingFlags.Static | BindingFlags.NonPublic);\n\n   public static Action<T, object> CreateSetter<T>(this PropertyInfo property)\n   {\n      if (property == null) throw new ArgumentNullException(nameof(property));\n\n      var setter = property.GetSetMethod(true);\n      if (setter == null) throw new ArgumentException($\"The specified property '{property.Name}' does not have a setter method.\");\n\n      var genericHelper = GenericSetterCreationMethod.MakeGenericMethod(property.DeclaringType, property.PropertyType);\n      return (Action<T, object>)genericHelper.Invoke(null, new object[] { setter });\n   }\n\n   private static Action<T, object> CreateSetterGeneric<T, V>(MethodInfo setter) where T : class\n   {\n      var setterTypedDelegate = \n#if STANDARD\n            (Action<T, V>) setter.CreateDelegate(typeof(Action<T, V>))\n#else\n            (Action<T, V>) Delegate.CreateDelegate(typeof(Action<T, V>), setter)\n#endif\n      ;\n      var setterDelegate = (Action<T, object>)((T instance, object value) => { setterTypedDelegate(instance, (V)value); });\n      return setterDelegate;\n   } \n","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/bchavez/Bogus/blob/6ece18c5c22648ab4606e45a0aaf2f07fc5259e4/Source/Bogus/Extensions/ExtensionsForPropertyInfo.cs#L1-L34","documentation":"ExtensionsForPropertyInfo.CreateSetter builds a delegate for a property's setter via reflection. If property.GetSetMethod(true) returns null - meaning the property is read-only (no set accessor at all, not even a non-public one) - it throws ArgumentException. The method is used internally by Faker<T> to wire RuleFor values onto properties.","triggerScenarios":"A RuleFor targeting a get-only property (e.g. `public string X { get; }` or `public string X => ...`) whose backing has no setter, when Faker tries to create a setter delegate for it.","commonSituations":"Mapping a Faker<T> onto a class with computed or init-only-without-setter properties, or onto a record with a get-only property that the generator tries to populate.","solutions":["Only declare RuleFor for properties that have a set accessor.","Add a setter to the target property (public or non-public - GetSetMethod(true) looks for non-public too).","Use RuleFor with a constructor/init path, or ignore the read-only property via FinishWith/omission."],"exampleFix":"// before\npublic class Model { public string Name { get; } }\nf.RuleFor(x => x.Name, _ => \"x\");\n\n// after\npublic class Model { public string Name { get; set; } }\nf.RuleFor(x => x.Name, _ => \"x\");","handlingStrategy":"validation","validationCode":"var setter = property.GetSetMethod(true);\nif (setter is null)\n    throw new InvalidOperationException($\"{property.Name} has no setter; cannot map via RuleFor.\");\n// only register RuleFor for settable properties","typeGuard":"static bool HasSetter(System.Reflection.PropertyInfo p) => p.GetSetMethod(true) is not null;","tryCatchPattern":null,"preventionTips":["Only target RuleFor at properties with a set accessor.","Filter mapped properties with HasSetter before configuring the Faker.","Prefer mutable DTOs/POCOs as Faker targets over records with get-only properties."],"tags":["reflection","property","argument-validation","faker"],"backgroundTag":null,"analyzedSha":"6ece18c5c22648ab4606e45a0aaf2f07fc5259e4","analyzedAt":"2026-08-13T21:08:15.463Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}