Repository navigation
Description
Describe the bug
This was discovered while checking the ref assemblies as part of the build simplification component of #4239, but it impacts multiple versions and the public-facing documentation.
We've never historically run ApiCompat to enforce identical API surfaces between the reference and the implementation assemblies. This was difficult to do pre-merge, and we still can't do so for netstandard2.0. I've been working on a PR which enables it and discovered that these API surfaces have diverged in a few ways:
- Missing
private/internalconstructors, so it appears to be possible to instantiate the type. - One erroneously-added property setter.
- Classes marked as
sealedin the implementation assembly and not in the reference assembly. - One enum which is present in the implementation assembly and not in the reference assembly.
- One method which is present in the reference assembly and not in the implementation assembly.
There also seem to be a few places where the public documentation doesn't match the offending members in the reference assemblies - I was expecting the missing constructors to be visible in both the netcore and netfx documentation, but only saw them in netcore.
To reproduce
Broken down by category:
Missing non-public constructors
Impact: MethodAccessException at runtime.
| Type | Implementation constructor | Documentation link |
|---|---|---|
| Microsoft.Data.Sql.SqlDataSourceEnumerator | private |
netcore |
| Microsoft.Data.SqlClient.SqlBatchCommandCollection | internal |
netcore |
| Microsoft.Data.SqlClient.SqlConnectionEncryptOption | private |
netcore |
| Microsoft.Data.SqlClient.Diagnostics.SqlClientCommandAfter | internal |
netcore |
| Microsoft.Data.SqlClient.Diagnostics.SqlClientCommandBefore | internal |
netcore |
| Microsoft.Data.SqlClient.Diagnostics.SqlClientCommandError | internal |
netcore |
| Microsoft.Data.SqlClient.Diagnostics.SqlClientConnectionCloseAfter | internal |
netcore |
| Microsoft.Data.SqlClient.Diagnostics.SqlClientConnectionCloseBefore | internal |
netcore |
| Microsoft.Data.SqlClient.Diagnostics.SqlClientConnectionCloseError | internal |
netcore |
| Microsoft.Data.SqlClient.Diagnostics.SqlClientConnectionOpenAfter | internal |
netcore |
| Microsoft.Data.SqlClient.Diagnostics.SqlClientConnectionOpenBefore | internal |
netcore |
| Microsoft.Data.SqlClient.Diagnostics.SqlClientConnectionOpenError | internal |
netcore |
| Microsoft.Data.SqlClient.Diagnostics.SqlClientTransactionCommitAfter | internal |
netcore |
| Microsoft.Data.SqlClient.Diagnostics.SqlClientTransactionCommitBefore | internal |
netcore |
| Microsoft.Data.SqlClient.Diagnostics.SqlClientTransactionCommitError | internal |
netcore |
| Microsoft.Data.SqlClient.Diagnostics.SqlClientTransactionRollbackAfter | internal |
netcore |
| Microsoft.Data.SqlClient.Diagnostics.SqlClientTransactionRollbackBefore | internal |
netcore |
| Microsoft.Data.SqlClient.Diagnostics.SqlClientTransactionRollbackError | internal |
netcore |
Erroneously-added property setter
Impact: MissingMethodException at runtime.
This is only the case on the netfx build of SqlBatchCommand - the setter for CanCreateParameter is present when it should not be.
Missing sealed modifier
Impact: TypeLoadException at runtime.
In all cases, the documentation for netcore varies from netfx. The netfx documentation includes the sealed modifier, which aligns with the implementation assembly but not the reference assembly; the netcore documentation leaves it out, which aligns with the reference assembly but not the implementation assembly.
- Microsoft.Data.SqlClient.DataClassification.ColumnSensitivity
- Microsoft.Data.SqlClient.DataClassification.InformationType
- Microsoft.Data.SqlClient.DataClassification.Label
- Microsoft.Data.SqlClient.DataClassification.SensitivityClassification
- Microsoft.Data.SqlClient.DataClassification.SensitivityProperty
Enum missing from reference assembly
Impact: Enum can't be accessed at compile time.
The Microsoft.Data.SqlClient.Server.TriggerAction enum is present in the implementation assembly for netfx, but missing from the netfx-compiled reference assembly. It's present in the documentation though.
Method missing from implementation assembly
Impact: MissingMethodException at runtime.
While the method is obsolete and hidden, SqlParameterCollection.Add(string, object) exists in the reference assembly but has no such method in the implementation assembly. Once again, this is only the case on netfx - on netcore, the method doesn't exist in the reference assembly at all.
I'd have expected this method to be visible in the documentation, but it doesn't appear in the overloads for Add.
Expected behavior
The API surfaces in the reference and the implementation assemblies for each TFM should match. API surfaces in the documentation should match.
Further technical details
Microsoft.Data.SqlClient versions: main. All builds of 7.1, 7.0, 6.1
.NET target: both TFMs
SQL Server version: N/A
Operating system: N/A
Additional context
I needed to fix this in the same PR which enables ApiCompat. I could split this in half so that it's easier to backport the API surface changes into the earlier releases, but I'm not clear on how or if you'd like to take them. The API removals and the correction of the sealed modifier would be a source-breaking change.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsBacklog
Activity
github-actions commentedon Oct 10, 2026
🔍 Triage Summary
main/7.1/7.0/6.1, both TFMs; SQL Server/OS N/A; detailed per-type repro list)Area\Engineering(ref/implementation API surface, ApiCompat build validation)Analysis
The reference assemblies under
src/Microsoft.Data.SqlClient/ref/diverge from the implementation for net462/net10.0. The issue lists missing non-public constructors, an extraSqlBatchCommand.CanCreateParametersetter on netfx, missingsealedon DataClassification types,Server.TriggerActionmissing from the netfx ref, andSqlParameterCollection.Add(string, object)present in the ref but absent in the implementation. Severity is P2: runtime failures are possible (MethodAccessException,MissingMethodException,TypeLoadException), but the affected paths are mostly edge cases. Fixes that remove API or addsealedare source-breaking and need a maintainer decision.Next Steps
ref/sources for each listed type. It should align constructors,sealedmodifiers, theCanCreateParametersetter,TriggerAction, andSqlParameterCollection.Add(string, object)with the implementation, and enable ApiCompat validation in the ref project.sealed, setter and method removal), and whether to backport to 6.1/7.0/7.1.doc/XML so netcore and netfx documentation match the corrected surfaces.edwardneal commentedon Oct 10, 2026
Adding an explicit non-public constructor is also a source-breaking change, because it suppresses the implicitly-generated public constructor.
Of the discrepancies, adding the new
TriggerActionenum to the reference assembly and theSqlParameterCollection.Add(string, object)method to the implementation assembly are additive changes. The others are technically source-breaking: they remove (either explicitly or implicitly) existing members from the API contract, or they block inheritance of existing types.edwardneal commentedon Nov 5, 2026
With #4832 and now #4890 merged, I think we've completed all of the work necessary for this on
main. Should any of this be backported to earlier releases?