DapperLib/Dapper · error · InvalidOperationException

Property setting not found for: {name}

Error message

Property setting not found for: {name}

What it means

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.

Source

Thrown at Dapper/DefaultTypeMap.cs:34

        /// <summary>
        /// Creates default type map
        /// </summary>
        /// <param name="type">Entity type</param>
        public DefaultTypeMap(Type type)
        {
            if (type is null)
                throw new ArgumentNullException(nameof(type));

            _fields = GetSettableFields(type);
            Properties = GetSettableProps(type);
            _type = type;
        }

        internal static MethodInfo GetPropertySetterOrThrow(PropertyInfo propertyInfo, Type type)
        {
            return GetPropertySetter(propertyInfo, type) ?? Throw(propertyInfo);

            static MethodInfo Throw(PropertyInfo propertyInfo) => throw new InvalidOperationException("Property setting not found for: " + propertyInfo?.Name);
        }
        internal static MethodInfo? GetPropertySetter(PropertyInfo propertyInfo, Type type)
        {
            if (propertyInfo.DeclaringType == type) return propertyInfo.GetSetMethod(true);

            return propertyInfo.DeclaringType!.GetProperty(
                   propertyInfo.Name,
                   BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
                   Type.DefaultBinder,
                   propertyInfo.PropertyType,
                   Array.ConvertAll(propertyInfo.GetIndexParameters(), p => p.ParameterType),
                   null)!.GetSetMethod(true);
        }

        internal static List<PropertyInfo> GetSettableProps(Type t)
        {
            return t
                  .GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)

View on GitHub (pinned to 72a54c475f)

Solutions

  1. Add a non-public setter to the property so GetSetMethod(true) can find it (e.g. public int Id { get; set; }).
  2. If the property genuinely has no setter, exclude it from mapping or supply a constructor-based map (CustomPropertyTypeMap / constructor matching).
  3. Avoid re-declaring/shadowing properties on derived types; prefer new writable properties with distinct names.

Example fix

// before
public class Derived : Base { public override string Name { get; } } // no setter

// after
public class Derived : Base { public override string Name { get; set; } }
Defensive patterns

Strategy: validation

Validate before calling

// static check: ensure mapped properties have setters
foreach (var prop in typeof(T).GetProperties())
    if (prop.GetSetMethod(true) is null && /* expected to be mapped */) { /* flag it */ }

Type guard

static bool HasSetter(PropertyInfo p) => p.GetSetMethod(true) is not null;

Try / catch

try { /* materialize into type */ }
catch (InvalidOperationException ex) when (ex.Message.StartsWith("Property setting not found"))
{ /* add a setter to the named property or use constructor mapping */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of DapperLib/Dapper@72a54c475f (2026-08-13). Data as JSON: /api/errors/b1dc6577bb7ae500. Report an issue: GitHub.