Skip to content

Error info is lost during serialization #2150

Closed

Description

@vnesterovsky

SqlException loses essential information about error, like error number, when goes through serialization.
Please consider saving relevant info to survive serialization round-trip.

See

si.AddValue("Errors", null); // Not specifying type to enable serialization of null value of non-serializable type

Activity

  1. JRahnama commented on Sep 12, 2023

    @JRahnama
    Contributor

    @vnesterovsky Thank you for reporting this issue. We will look into this and will get back to you.

  2. moved this from To triage to Backlog in SqlClient Boardon Jan 9, 2026
  3. moved this from Backlog to In progress in SqlClient Boardon Sep 2, 2026
  4. priyankatiwari08 commented on Sep 17, 2026

    @priyankatiwari08
    Contributor

    /triage

  5. github-actions commented on Sep 17, 2026

    @github-actions

    🔍 Triage Summary (on-demand re-triage)

    Check Result
    Issue type Bug
    Environment ⚠️ Missing: SqlClient version, .NET target framework, SQL Server version, Operating system, minimal repro steps
    Area Area\Engineering
    Duplicates Potentially related: #1940 (SqlException.Number always 0 across .NET Remoting serialization boundary)
    Regression Not indicated

    Analysis

    SqlException.GetObjectData() intentionally nulls out the internal Errors/SqlErrorCollection during serialization, so properties such as Number, LineNumber, Class, Server, and Procedure (which are all derived from the first SqlError in that collection) come back as default values after a serialization round-trip (e.g. .NET Remoting, cross-AppDomain, or custom binary serialization). This is a real, previously-acknowledged design gap in SqlException/SqlErrorCollection serialization rather than a regression, and is closely related to #1940. There is already an open pull request, #4622 ("Fix | Enable serialization of SqlException"), that appears to address this exact gap. Severity: P2 (data-fidelity/diagnostics issue, not a crash or data-corruption bug, but it hampers error handling in serialization scenarios such as remoting or cross-process boundaries).

    Next Steps

    • Since a fix is already in flight, prioritize reviewing and progressing PR Fix | Enable serialization of SqlException #4622 rather than starting new investigation from scratch — verify it restores Number, LineNumber, Class, Server, Procedure, and other SqlError-derived fields through a full serialize/deserialize round-trip, and that it adds regression tests covering both BinaryFormatter-style and any other supported serialization paths.
    • Recommend reviewing SqlException.Number is always 0 when using .NET framework remoting #1940 alongside this issue, since both stem from the same root cause (SqlErrorCollection not being preserved through GetObjectData/deserialization constructor) — a single fix may be able to close both.
    • @vnesterovsky, if you have a minimal repro (e.g., a short console sample serializing/deserializing a SqlException via BinaryFormatter or another serializer) along with your Microsoft.Data.SqlClient version, .NET target framework, SQL Server version, and OS, please share them so reviewers can validate PR Fix | Enable serialization of SqlException #4622 against your exact scenario.

    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 #2150 · copilot · auto · 70.9 AIC · ⌖ 13.1 AIC · ⊞ 11.9K · ◷

  6. moved this from In progress to Done in SqlClient Boardon Oct 29, 2026
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