{"record":{"id":"8a7b15794ada887c","repo":"HangfireIO/Hangfire","slug":"net-core-version-of-the-system-data-sqlclient-pac","errorCode":null,"errorMessage":".NET Core version of the System.Data.SqlClient package below 4.7.0 (which has assembly version 4.6.0.0) doesn't properly implement the SqlCommandSet class.","messagePattern":"\\.NET Core version of the System\\.Data\\.SqlClient package below 4\\.7\\.0 \\(which has assembly version 4\\.6\\.0\\.0\\) doesn't properly implement the SqlCommandSet class\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.SqlServer/SqlCommandSet.cs","lineNumber":64,"sourceCode":"\n        public SqlCommandSet(DbConnection connection)\n        {\n            Type sqlCommandSetType;\n            try\n            {\n                sqlCommandSetType = SqlCommandSetType.GetOrAdd(connection.GetType().GetTypeInfo().Assembly, static sqlClientAssembly =>\n                {\n                    var assemblyName = sqlClientAssembly.GetName();\n                    var version = assemblyName.Version;\n\n                    if (assemblyName.Name == \"System.Data.SqlClient\" && Version.Parse(\"4.0.0.0\") < version && version < Version.Parse(\"4.6.0.0\"))\n                    {\n                        // .NET Core version of the System.Data.SqlClient package below 4.7.0 (which\n                        // has assembly version 4.6.0.0) doesn't properly implement the SqlCommandSet\n                        // class, throwing the following exception in run-time:\n                        // ArgumentException: Specified parameter name 'Parameter1' is not valid.\n                        // GitHub Issue: https://github.com/dotnet/corefx/issues/29391\n                        throw new NotSupportedException(\".NET Core version of the System.Data.SqlClient package below 4.7.0 (which has assembly version 4.6.0.0) doesn't properly implement the SqlCommandSet class.\");\n                    }\n\n                    var type = sqlClientAssembly.GetTypes().FirstOrDefault(static x => x.Name == \"SqlCommandSet\");\n                    if (type == null)\n                    {\n                        throw new TypeLoadException($\"Could not load type 'SqlCommandSet' from assembly '{sqlClientAssembly}'.\");\n                    }\n\n                    return type;\n                });\n\n                _setConnection = SetConnection.GetOrAdd(sqlCommandSetType, static type =>\n                {\n                    var p = Expression.Parameter(typeof(object));\n                    var converted = Expression.Convert(p, type);\n                    var connectionParameter = Expression.Parameter(typeof(DbConnection));\n                    var connectionProperty = type.GetProperty(\"Connection\", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) ?? throw new MissingMemberException($\"Property '{type.FullName}.Connection' not found.\");\n                    return Expression.Lambda<Action<object, DbConnection>>(Expression.Assign(Expression.Property(converted, connectionProperty), Expression.Convert(connectionParameter, connectionProperty.PropertyType)), p, connectionParameter).Compile();","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.SqlServer/SqlCommandSet.cs#L46-L82","documentation":"NotSupportedException thrown by SqlCommandSet's lazy type loader when the resolved sqlClientAssembly is named 'System.Data.SqlClient' and its assembly version is greater than 4.0.0.0 but less than 4.6.0.0. Those .NET Core package versions (< 4.7.0 NuGet, assembly 4.6.0.0) ship a broken SqlCommandSet that throws 'Specified parameter name is not valid' at runtime (corefx #29391), so Hangfire refuses to use batch commands on them.","triggerScenarios":"Using Hangfire.SqlServer on .NET Core/5+ with the System.Data.SqlClient NuGet package pinned below 4.7.0 while Hangfire attempts to batch commands.","commonSituations":"Inheriting an older packages.lock or transitive dependency on System.Data.SqlClient < 4.7.0; CI restoring an old cached package; a transitive dependency forcing the older version.","solutions":["Upgrade the System.Data.SqlClient NuGet package to 4.7.0 or later (ideally the newest 4.8.x).","Switch to Microsoft.Data.SqlClient which does not hit this assembly-version range.","Run dotnet list package --outdated and pin a minimum version in your .csproj to prevent downgrade."],"exampleFix":"// before\n<PackageReference Include=\"System.Data.SqlClient\" Version=\"4.6.1\" />\n\n// after\n<PackageReference Include=\"System.Data.SqlClient\" Version=\"4.8.6\" />","handlingStrategy":"validation","validationCode":"// build-time check\nvar asm = typeof(SqlConnection).Assembly.GetName();\nif (asm.Name == \"System.Data.SqlClient\"\n    && Version.Parse(\"4.0.0.0\") < asm.Version && asm.Version < Version.Parse(\"4.6.0.0\"))\n    throw new InvalidOperationException(\"Upgrade System.Data.SqlClient to >= 4.7.0.\");","typeGuard":null,"tryCatchPattern":"try { /* batch insert path */ }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"SqlCommandSet\"))\n{\n    // fall back to regular, non-batched command execution\n}","preventionTips":["Pin System.Data.SqlClient to >= 4.8.x in Directory.Packages.props.","Prefer Microsoft.Data.SqlClient for new projects.","Run dotnet list package --outdated in CI."],"tags":["sqlserver","versioning","dependency","not-supported"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}