{"record":{"id":"b1dc6577bb7ae500","repo":"DapperLib/Dapper","slug":"property-setting-not-found-for-name","errorCode":null,"errorMessage":"Property setting not found for: {name}","messagePattern":"Property setting not found for: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Dapper/DefaultTypeMap.cs","lineNumber":34,"sourceCode":"        /// <summary>\r\n        /// Creates default type map\r\n        /// </summary>\r\n        /// <param name=\"type\">Entity type</param>\r\n        public DefaultTypeMap(Type type)\r\n        {\r\n            if (type is null)\r\n                throw new ArgumentNullException(nameof(type));\r\n\r\n            _fields = GetSettableFields(type);\r\n            Properties = GetSettableProps(type);\r\n            _type = type;\r\n        }\r\n\r\n        internal static MethodInfo GetPropertySetterOrThrow(PropertyInfo propertyInfo, Type type)\r\n        {\r\n            return GetPropertySetter(propertyInfo, type) ?? Throw(propertyInfo);\r\n\r\n            static MethodInfo Throw(PropertyInfo propertyInfo) => throw new InvalidOperationException(\"Property setting not found for: \" + propertyInfo?.Name);\r\n        }\r\n        internal static MethodInfo? GetPropertySetter(PropertyInfo propertyInfo, Type type)\r\n        {\r\n            if (propertyInfo.DeclaringType == type) return propertyInfo.GetSetMethod(true);\r\n\r\n            return propertyInfo.DeclaringType!.GetProperty(\r\n                   propertyInfo.Name,\r\n                   BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,\r\n                   Type.DefaultBinder,\r\n                   propertyInfo.PropertyType,\r\n                   Array.ConvertAll(propertyInfo.GetIndexParameters(), p => p.ParameterType),\r\n                   null)!.GetSetMethod(true);\r\n        }\r\n\r\n        internal static List<PropertyInfo> GetSettableProps(Type t)\r\n        {\r\n            return t\r\n                  .GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)\r","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/DapperLib/Dapper/blob/72a54c475f75e18cb93cba0809d00a5e6e49efd9/Dapper/DefaultTypeMap.cs#L16-L52","documentation":"DefaultTypeMap.GetPropertySetterOrThrow throws InvalidOperationException(\"Property setting not found for: {name}\") when GetPropertySetter returns null — i.e. no set accessor could be resolved for the property (the property is read-only, or a re-declared property on a derived type has no accessible setter). This is hit during Dapper's member-resolution path when building setters for materialized objects.","triggerScenarios":"Materializing into a type whose property is get-only (no setter) and is re-declared/shadowed on a derived class so the base setter cannot be located; using a type with init-only or readonly properties that Dapper treats as settable but for which reflection finds no set method.","commonSituations":"DTO/entity with computed or read-only properties that shadow base members; records or immutable types where the canonical setter is the constructor, not a property setter; inheriting from a base library type whose property has no setter override.","solutions":["Add a non-public setter to the property so GetSetMethod(true) can find it (e.g. public int Id { get; set; }).","If the property genuinely has no setter, exclude it from mapping or supply a constructor-based map (CustomPropertyTypeMap / constructor matching).","Avoid re-declaring/shadowing properties on derived types; prefer new writable properties with distinct names."],"exampleFix":"// before\npublic class Derived : Base { public override string Name { get; } } // no setter\n\n// after\npublic class Derived : Base { public override string Name { get; set; } }","handlingStrategy":"validation","validationCode":"// static check: ensure mapped properties have setters\nforeach (var prop in typeof(T).GetProperties())\n    if (prop.GetSetMethod(true) is null && /* expected to be mapped */) { /* flag it */ }","typeGuard":"static bool HasSetter(PropertyInfo p) => p.GetSetMethod(true) is not null;","tryCatchPattern":"try { /* materialize into type */ }\ncatch (InvalidOperationException ex) when (ex.Message.StartsWith(\"Property setting not found\"))\n{ /* add a setter to the named property or use constructor mapping */ }","preventionTips":["Ensure materialized DTO properties have at least a non-public setter.","Avoid shadowing properties on derived types; use distinct writable properties."],"tags":["type-map","reflection","setter","materialization"],"backgroundTag":null,"analyzedSha":"72a54c475f75e18cb93cba0809d00a5e6e49efd9","analyzedAt":"2026-08-13T14:18:18.115Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}