{"record":{"id":"635c9d4792a7408b","repo":"DapperLib/Dapper","slug":"cannot-be-null-or-empty","errorCode":null,"errorMessage":"Cannot be null or empty","messagePattern":"Cannot be null or empty","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Dapper/UdtTypeHandler.cs","lineNumber":21,"sourceCode":"\r\nnamespace Dapper\r\n{\r\n    public static partial class SqlMapper\r\n    {\r\n        /// <summary>\r\n        /// A type handler for data-types that are supported by the underlying provider, but which need\r\n        /// a well-known UdtTypeName to be specified\r\n        /// </summary>\r\n        public class UdtTypeHandler : ITypeHandler\r\n        {\r\n            private readonly string udtTypeName;\r\n            /// <summary>\r\n            /// Creates a new instance of UdtTypeHandler with the specified <see cref=\"UdtTypeHandler\"/>.\r\n            /// </summary>\r\n            /// <param name=\"udtTypeName\">The user defined type name.</param>\r\n            public UdtTypeHandler(string udtTypeName)\r\n            {\r\n                if (string.IsNullOrEmpty(udtTypeName)) throw new ArgumentException(\"Cannot be null or empty\", udtTypeName);\r\n                this.udtTypeName = udtTypeName;\r\n            }\r\n\r\n            object? ITypeHandler.Parse(Type destinationType, object value)\r\n            {\r\n                return value is DBNull ? null : value;\r\n            }\r\n\r\n            void ITypeHandler.SetValue(IDbDataParameter parameter, object value)\r\n            {\r\n#pragma warning disable 0618\r\n                parameter.Value = SanitizeParameterValue(value);\r\n#pragma warning restore 0618\r\n                if(!(value is DBNull)) StructuredHelper.ConfigureUDT(parameter, udtTypeName);\r\n            }\r\n        }\r\n    }\r\n}\r","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/DapperLib/Dapper/blob/72a54c475f75e18cb93cba0809d00a5e6e49efd9/Dapper/UdtTypeHandler.cs#L3-L39","documentation":"Thrown by the `SqlMapper.UdtTypeHandler` constructor when `udtTypeName` is null or empty. The handler needs a concrete UDT type name to set on `SqlDbType.Udt` parameters (SqlMapper.UdtTypeHandler.SetValue uses it as parameter.UdtTypeName); an empty name would produce an invalid provider call, so it is rejected at construction with ArgumentException.","triggerScenarios":"Calling `new SqlMapper.UdtTypeHandler(null)` or `new SqlMapper.UdtTypeHandler(\"\")`, or registering a type handler with a UDT name read from configuration that is missing/blank.","commonSituations":"Loading the UDT name from appsettings/environment and the key is absent; copy-pasting handler registration and forgetting the name; whitespace-only string (note: the check is IsNullOrEmpty, so a whitespace-only name passes but later fails at the provider).","solutions":["Supply the real UDT type name, e.g. `new SqlMapper.UdtTypeHandler(\"dbo.Geography\")`.","Validate/load the UDT name from configuration with a default and a clear error if missing.","Trim the value and check it is non-empty before constructing the handler.","If you do not need UDT handling, remove the handler registration."],"exampleFix":"// before\nSqlMapper.AddTypeHandler(typeof(Geo), new SqlMapper.UdtTypeHandler(config[\"UdtName\"])); // config value missing -> null\n// after\nvar udt = config[\"UdtName\"] ?? throw new InvalidOperationException(\"UdtName not configured\");\nSqlMapper.AddTypeHandler(typeof(Geo), new SqlMapper.UdtTypeHandler(udt));","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(udtTypeName)) throw new ArgumentException(\"UDT name required\", nameof(udtTypeName));\nvar handler = new SqlMapper.UdtTypeHandler(udtTypeName.Trim());","typeGuard":"static bool IsValidUdtName(string? s) => !string.IsNullOrWhiteSpace(s);","tryCatchPattern":null,"preventionTips":["Validate the UDT name from configuration with a default/error.","Trim the value and reject whitespace (the ctor only checks IsNullOrEmpty).","Register UDT handlers once at startup with a known-good name."],"tags":["dapper","udt","typehandler","argument","validation"],"backgroundTag":null,"analyzedSha":"72a54c475f75e18cb93cba0809d00a5e6e49efd9","analyzedAt":"2026-08-13T14:18:18.115Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}