{"record":{"id":"de4142c0b9de2ed0","repo":"aspnetboilerplate/aspnetboilerplate","slug":"nameof-sql-cannot-be-null-or-empty-de4142","errorCode":null,"errorMessage":"{nameof(sql)} cannot be null or empty.","messagePattern":"(.+?) cannot be null or empty\\.","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Abp.Dapper/Dapper-Extensions/Sql/SqlDialectBase.cs","lineNumber":156,"sourceCode":"        {\n            return value;\n        }\n        return string.Format(\"{0}{1}{2}\", OpenQuote, value.Trim(), CloseQuote);\n    }\n\n    public virtual string UnQuoteString(string value)\n    {\n        return IsQuoted(value) ? value.Substring(1, value.Length - 2) : value;\n    }\n\n    public abstract string GetDatabaseFunctionString(DatabaseFunction databaseFunction, string columnName, string functionParameters = \"\");\n\n    public abstract void EnableCaseInsensitive(IDbConnection connection);\n\n    public virtual string GetCountSql(string sql)\n    {\n        if (string.IsNullOrEmpty(sql))\n            throw new ArgumentNullException(nameof(sql), $\"{nameof(sql)} cannot be null or empty.\");\n\n        if (string.IsNullOrWhiteSpace(sql))\n            throw new ArgumentNullException(nameof(sql), $\"{nameof(sql)} cannot be null or empty.\");\n\n        return $\"SELECT COUNT(*) AS {OpenQuote}Total{CloseQuote} FROM {sql}\";\n    }\n\n    protected virtual bool IsSelectSql(string sql)\n    {\n        return sql.Trim().StartsWith(\"SELECT\", StringComparison.InvariantCultureIgnoreCase);\n    }\n}","sourceCodeStart":138,"sourceCodeEnd":168,"githubUrl":"https://github.com/aspnetboilerplate/aspnetboilerplate/blob/2323c13a152aa0ebfb37af3830f687d7f5b53795/src/Abp.Dapper/Dapper-Extensions/Sql/SqlDialectBase.cs#L138-L168","documentation":"SqlDialectBase.GetCountSql wraps a SQL fragment in a SELECT COUNT(*) query, but requires the inner sql string to be non-empty and non-whitespace. When null or empty is passed, it throws ArgumentNullException naming the 'sql' parameter. The message renders the literal string '{nameof(sql)}' because the interpolated nameof expression was written inside a quoted string rather than being evaluated.","triggerScenarios":"Calling GetCountSql(null) or GetCountSql(\"\") or GetCountSql(\"   \") on an ISqlDialect instance, directly or through code that builds a count query from an uninitialized SQL fragment.","commonSituations":"Building count queries dynamically where the base SQL string variable was never assigned or was trimmed to empty; overriding dialect methods and calling base.GetCountSql with a derived value that can be null.","solutions":["Ensure the sql string passed to GetCountSql is a non-empty, non-whitespace SQL fragment before calling","Guard the caller: check string.IsNullOrWhiteSpace(sql) upstream and handle it instead of calling GetCountSql","If this is your own dialect override, validate inputs before calling base.GetCountSql"],"exampleFix":"// before\nvar countSql = dialect.GetCountSql(sqlFragment);\n// after\nvar countSql = string.IsNullOrWhiteSpace(sqlFragment)\n    ? null\n    : dialect.GetCountSql(sqlFragment);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(sql)) throw new ArgumentException(\"A non-empty SQL fragment is required before calling GetCountSql.\", nameof(sql));","typeGuard":null,"tryCatchPattern":"try { countSql = dialect.GetCountSql(sql); } catch (ArgumentNullException ex) when (ex.ParamName == \"sql\") { /* fall back to manual count query or rethrow with context */ }","preventionTips":["Never pass user-supplied or dynamically built SQL fragments without IsNullOrWhiteSpace checks","Keep SQL fragment builders returning validated non-empty strings"],"tags":["csharp","argument-validation","dapper","null-argument"],"backgroundTag":"null-argument","analyzedSha":"2323c13a152aa0ebfb37af3830f687d7f5b53795","analyzedAt":"2026-09-08T08:00:50.638Z","contentChangedAt":"2026-09-08T08:00:50.638Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}