Skip to content

ref/ assemblies do not match implementation assembly API surfaces #4826

Open

Description

@edwardneal

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/internal constructors, so it appears to be possible to instantiate the type.
  • One erroneously-added property setter.
  • Classes marked as sealed in 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.

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.

Activity

  1. added theissue type on Oct 10, 2026
  2. github-actions commented on Oct 10, 2026

    @github-actions

    🔍 Triage Summary

    Check Result
    Issue type Bug
    Environment All required environment details provided for investigation (SqlClient main/7.1/7.0/6.1, both TFMs; SQL Server/OS N/A; detailed per-type repro list)
    Area Area\Engineering (ref/implementation API surface, ApiCompat build validation)
    Duplicates None found
    Regression Not indicated (long-standing divergence across 6.1–7.1)

    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 extra SqlBatchCommand.CanCreateParameter setter on netfx, missing sealed on DataClassification types, Server.TriggerAction missing from the netfx ref, and SqlParameterCollection.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 add sealed are source-breaking and need a maintainer decision.

    Next Steps

    • Assign this issue to Copilot coding agent to investigate the ref/ sources for each listed type. It should align constructors, sealed modifiers, the CanCreateParameter setter, TriggerAction, and SqlParameterCollection.Add(string, object) with the implementation, and enable ApiCompat validation in the ref project.
    • Maintainers should decide whether to split the non-breaking fixes (constructors, enum) from the source-breaking ones (sealed, setter and method removal), and whether to backport to 6.1/7.0/7.1.
    • Update doc/ XML so netcore and netfx documentation match the corrected surfaces.

    Note: This triage summary is auto-generated by an AI agent. The analysis and suggestions above have not been verified by a human maintainer. Please treat as preliminary guidance only.

    Generated by SqlClient Issue Auto-Triage for #4826 · copilot · auto · 23.3 AIC · ⌖ 11.5 AIC · ⊞ 13.5K · ◷

  3. edwardneal commented on Oct 10, 2026

    @edwardneal
    ContributorAuthor

    2. Fixes that remove API or add sealed are source-breaking and need a maintainer decision.

    Maintainers should decide whether to split the non-breaking fixes (constructors, enum) from the source-breaking ones (sealed, setter and method removal), and whether to backport to 6.1/7.0/7.1.

    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 TriggerAction enum to the reference assembly and the SqlParameterCollection.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.

  4. moved this from To triage to Backlog in SqlClient Boardon Oct 13, 2026
  5. edwardneal commented on Nov 5, 2026

    @edwardneal
    ContributorAuthor

    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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions