{"record":{"id":"a8d4d545f06c6dac","repo":"DapperLib/Dapper","slug":"type-a8d4d5","errorCode":null,"errorMessage":"type","messagePattern":"type","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Dapper/DefaultTypeMap.cs","lineNumber":23,"sourceCode":"\r\nnamespace Dapper\r\n{\r\n    /// <summary>\r\n    /// Represents default type mapping strategy used by Dapper\r\n    /// </summary>\r\n    public sealed class DefaultTypeMap : SqlMapper.ITypeMap\r\n    {\r\n        private readonly FieldInfo[] _fields;\r\n        private readonly Type _type;\r\n\r\n        /// <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","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/DapperLib/Dapper/blob/72a54c475f75e18cb93cba0809d00a5e6e49efd9/Dapper/DefaultTypeMap.cs#L5-L41","documentation":"DefaultTypeMap's constructor rejects a null type with ArgumentNullException(nameof(type)). The map immediately calls GetSettableFields/GetSettableProps on the type, which would NullReferenceException without this guard. This is the standard type-map entry point used internally by Dapper for materialization.","triggerScenarios":"Constructing new DefaultTypeMap(null); Dapper internals attempting to build a type map for a type that resolved to null (e.g. Type.GetType on a bad name); calling SqlMapper.SetTypeMap(type, map) where type is null.","commonSituations":"Reflection-based type loading where Type.GetType returned null because the assembly-qualified name was wrong or the assembly was not referenced; dynamically building maps from config with a missing type entry.","solutions":["Validate the Type is non-null before constructing the map; guard Type.GetType results explicitly.","Correct the assembly-qualified type name string and ensure the containing assembly is loaded."],"exampleFix":"// before\nvar map = new DefaultTypeMap(Type.GetType(modelName));\n\n// after\nvar type = Type.GetType(modelName) ?? throw new InvalidOperationException($\"Unknown type: {modelName}\");\nvar map = new DefaultTypeMap(type);","handlingStrategy":"validation","validationCode":"var type = Type.GetType(modelName) ?? throw new InvalidOperationException($\"Unknown type: {modelName}\");\nvar map = new DefaultTypeMap(type);","typeGuard":"static Type RequireType(Type? t, string name) => t ?? throw new ArgumentNullException(name);","tryCatchPattern":null,"preventionTips":["Validate Type.GetType results before building maps.","Resolve types once at startup and cache the Type instances."],"tags":["argument-null","type-map","materialization"],"backgroundTag":null,"analyzedSha":"72a54c475f75e18cb93cba0809d00a5e6e49efd9","analyzedAt":"2026-08-13T14:18:18.115Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}