You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SqlException loses essential information about error, like error number, when goes through serialization.
Please consider saving relevant info to survive serialization round-trip.
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.
Activity
JRahnama commentedon Sep 12, 2023
@vnesterovsky Thank you for reporting this issue. We will look into this and will get back to you.
priyankatiwari08 commentedon Sep 17, 2026
/triage
github-actions commentedon Sep 17, 2026
🔍 Triage Summary (on-demand re-triage)
Area\EngineeringAnalysis
SqlException.GetObjectData()intentionally nulls out the internalErrors/SqlErrorCollectionduring serialization, so properties such asNumber,LineNumber,Class,Server, andProcedure(which are all derived from the firstSqlErrorin 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 inSqlException/SqlErrorCollectionserialization 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
Number,LineNumber,Class,Server,Procedure, and otherSqlError-derived fields through a full serialize/deserialize round-trip, and that it adds regression tests covering bothBinaryFormatter-style and any other supported serialization paths.SqlErrorCollectionnot being preserved throughGetObjectData/deserialization constructor) — a single fix may be able to close both.SqlExceptionviaBinaryFormatteror 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.