{"record":{"id":"b616bb46415bf840","repo":"DapperLib/Dapper","slug":"type","errorCode":null,"errorMessage":"type","messagePattern":"type","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Dapper/CustomPropertyTypeMap.cs","lineNumber":21,"sourceCode":"\r\nnamespace Dapper\r\n{\r\n    /// <summary>\r\n    /// Implements custom property mapping by user provided criteria (usually presence of some custom attribute with column to member mapping)\r\n    /// </summary>\r\n    public sealed class CustomPropertyTypeMap : SqlMapper.ITypeMap\r\n    {\r\n        private readonly Type _type;\r\n        private readonly Func<Type, string, PropertyInfo> _propertySelector;\r\n\r\n        /// <summary>\r\n        /// Creates custom property mapping\r\n        /// </summary>\r\n        /// <param name=\"type\">Target entity type</param>\r\n        /// <param name=\"propertySelector\">Property selector based on target type and DataReader column name</param>\r\n        public CustomPropertyTypeMap(Type type, Func<Type, string, PropertyInfo> propertySelector)\r\n        {\r\n            _type = type ?? throw new ArgumentNullException(nameof(type));\r\n            _propertySelector = propertySelector ?? throw new ArgumentNullException(nameof(propertySelector));\r\n        }\r\n\r\n        /// <summary>\r\n        /// Always returns default constructor\r\n        /// </summary>\r\n        /// <param name=\"names\">DataReader column names</param>\r\n        /// <param name=\"types\">DataReader column types</param>\r\n        /// <returns>Default constructor</returns>\r\n        public ConstructorInfo? FindConstructor(string[] names, Type[] types) =>\r\n            _type.GetConstructor(Array.Empty<Type>())!;\r\n\r\n        /// <summary>\r\n        /// Always returns null\r\n        /// </summary>\r\n        /// <returns></returns>\r\n        public ConstructorInfo? FindExplicitConstructor() => null;\r\n\r","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/DapperLib/Dapper/blob/72a54c475f75e18cb93cba0809d00a5e6e49efd9/Dapper/CustomPropertyTypeMap.cs#L3-L39","documentation":"CustomPropertyTypeMap's constructor rejects a null type argument with ArgumentNullException(nameof(type)). The map needs the target entity Type to resolve properties at construction time, so a null type is unrecoverable. The same guard applies to the propertySelector delegate.","triggerScenarios":"Constructing new CustomPropertyTypeMap(null, selector) or passing a type resolved dynamically that came back null (e.g. Type.GetType(\"Missing.Namespace.Foo\") returned null). Registering a custom map via SqlMapper.SetTypeMap with a null type.","commonSituations":"Type.GetType with a misspelled/assembly-qualified name returning null; reflection-driven code that loads entity types from config where a name was wrong; generics where typeof() was replaced by a variable that lost its value.","solutions":["Resolve the Type before construction and throw a clearer error if null (e.g. guard Type.GetType results).","Verify the assembly-qualified type name string is correct and the assembly is loaded/referenced."],"exampleFix":"// before\nvar map = new CustomPropertyTypeMap(Type.GetType(configType), (t, col) => ...);\n\n// after\nvar type = Type.GetType(configType) ?? throw new InvalidOperationException($\"Unknown type: {configType}\");\nvar map = new CustomPropertyTypeMap(type, (t, col) => ...);","handlingStrategy":"validation","validationCode":"var type = Type.GetType(modelName) ?? throw new InvalidOperationException($\"Unknown type: {modelName}\");\nvar map = new CustomPropertyTypeMap(type, (t, col) => t.GetProperty(col));","typeGuard":"static Type RequireType(Type? t, string name) => t ?? throw new ArgumentNullException(name);","tryCatchPattern":null,"preventionTips":["Always null-check Type.GetType results before use.","Keep entity type names in a single config source and validate them at startup."],"tags":["argument-null","type-map","reflection"],"backgroundTag":null,"analyzedSha":"72a54c475f75e18cb93cba0809d00a5e6e49efd9","analyzedAt":"2026-08-13T14:18:18.115Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}