{"record":{"id":"1844fbf7289731f4","repo":"DapperLib/Dapper","slug":"a-parameterless-default-constructor-or-one-matchin","errorCode":null,"errorMessage":"A parameterless default constructor or one matching signature {proposedTypes} is required for {type.FullName} materialization","messagePattern":"A parameterless default constructor or one matching signature (.+?) is required for (.+?) materialization","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Dapper/SqlMapper.cs","lineNumber":3528,"sourceCode":"                        }\r\n                    }\r\n\r\n                    il.Emit(OpCodes.Newobj, explicitConstr);\r\n                    il.Emit(OpCodes.Stloc, returnValueLocal);\r\n                    supportInitialize = typeof(ISupportInitialize).IsAssignableFrom(type);\r\n                    if (supportInitialize)\r\n                    {\r\n                        il.Emit(OpCodes.Ldloc, returnValueLocal);\r\n                        il.EmitCall(OpCodes.Callvirt, typeof(ISupportInitialize).GetMethod(nameof(ISupportInitialize.BeginInit))!, null);\r\n                    }\r\n                }\r\n                else\r\n                {\r\n                    var ctor = typeMap.FindConstructor(names, types);\r\n                    if (ctor is null)\r\n                    {\r\n                        string proposedTypes = \"(\" + string.Join(\", \", types.Select((t, i) => t.FullName + \" \" + names[i]).ToArray()) + \")\";\r\n                        throw new InvalidOperationException($\"A parameterless default constructor or one matching signature {proposedTypes} is required for {type.FullName} materialization\");\r\n                    }\r\n\r\n                    if (ctor.GetParameters().Length == 0)\r\n                    {\r\n                        il.Emit(OpCodes.Newobj, ctor);\r\n                        il.Emit(OpCodes.Stloc, returnValueLocal);\r\n                        supportInitialize = typeof(ISupportInitialize).IsAssignableFrom(type);\r\n                        if (supportInitialize)\r\n                        {\r\n                            il.Emit(OpCodes.Ldloc, returnValueLocal);\r\n                            il.EmitCall(OpCodes.Callvirt, typeof(ISupportInitialize).GetMethod(nameof(ISupportInitialize.BeginInit))!, null);\r\n                        }\r\n                    }\r\n                    else\r\n                    {\r\n                        specializedConstructor = ctor;\r\n                    }\r\n                }\r","sourceCodeStart":3510,"sourceCodeEnd":3546,"githubUrl":"https://github.com/DapperLib/Dapper/blob/72a54c475f75e18cb93cba0809d00a5e6e49efd9/Dapper/SqlMapper.cs#L3510-L3546","documentation":"Thrown during deserializer IL generation when `typeMap.FindConstructor(names, types)` returns null — i.e. the target type has neither a parameterless constructor nor a constructor whose parameters match the result-set column names/types. Dapper needs a way to instantiate the type; with no usable ctor it cannot proceed, so it reports the expected signature in the message and throws InvalidOperationException.","triggerScenarios":"Mapping a query onto a class/struct that has only constructors whose parameter names do not match any result columns, or no public constructor at all (e.g. an interface, an abstract class, a class with only a private ctor, or a DTO whose ctor params differ from the column names). Also when column names differ from both property names and ctor parameter names.","commonSituations":"Mapping to a record/struct whose constructor parameter names do not match the SQL column names; mapping onto an interface; a column renamed in the DB without updating the DTO ctor; a type with no default ctor where the only ctor takes unrelated types.","solutions":["Add a parameterless constructor to the type (properties will then be set by name).","Align constructor parameter names with the result column names (case-insensitive), or alias columns in SQL to match the ctor params.","Use a CustomPropertyTypeMap / SetTypeMap to specify the exact constructor to use.","Map onto a concrete class with settable properties instead of an interface or a ctor-only struct whose names mismatch."],"exampleFix":"// before\npublic class User { public User(int userId) {} public string Name {get;set;} }\n// select returns columns: Id, Name  -> 'userId' ctor does not match 'Id'\n// after: add parameterless ctor or rename\npublic class User { public User() {} public int Id {get;set;} public string Name {get;set;} }","handlingStrategy":"validation","validationCode":"// Ensure the target type has a parameterless ctor or a ctor matching column names.\nvar hasDefaultCtor = typeof(T).GetConstructor(Type.EmptyTypes) is not null;\nif (!hasDefaultCtor) throw new InvalidOperationException(typeof(T).Name + \" needs a parameterless ctor or ctor params matching the columns.\");","typeGuard":"static bool IsMaterializable(Type t) => t.GetConstructor(Type.EmptyTypes) is not null || t.GetConstructors().Any(c => c.GetParameters().Length > 0);","tryCatchPattern":null,"preventionTips":["Add a parameterless constructor to mapped types.","Align ctor parameter names with SQL column names (or alias columns).","Use SetTypeMap/CustomPropertyTypeMap to pin a specific constructor.","Map onto concrete classes, not interfaces or abstract types."],"tags":["dapper","materialization","constructor","typemap"],"backgroundTag":null,"analyzedSha":"72a54c475f75e18cb93cba0809d00a5e6e49efd9","analyzedAt":"2026-08-13T14:18:18.115Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}