Fix | Enable serialization of SqlException - #4622
Open
edwardneal wants to merge 2 commits into
Open
edwardneal wants to merge 2 commits into
edwardneal wants to merge 2 commits into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
This was referenced Sep 17, 2026
paulmedynski
previously approved these changes
Sep 29, 2026
Contributor
|
/azp run |
|
Azure Pipelines: Successfully started running 2 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. |
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The new test class and method lack required XML summary documentation.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Fixes SqlException serialization so SQL error details survive .NET Framework formatter round trips.
Changes:
- Serializes and restores
SqlErrorCollection. - Adds a BinaryFormatter regression test.
| File | Description |
|---|---|
SqlException.cs |
Persists errors during serialization. |
SqlExceptionTests.cs |
Tests serialized exception state. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
paulmedynski
approved these changes
Sep 29, 2026
Contributor
|
/azp run |
|
Azure Pipelines: Successfully started running 2 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
This fixes two longstanding bugs when serializing a SqlException using .NET Framework's
SerializableAttribute-based infrastructure - via DataContractSerializer, BinaryFormatter or SoapFormatter.The underlying bug was simply that we weren't providing a value for the
Errorscollection inGetObjectData, or reading it back in the deserialization constructor. Since properties such asSqlException.Numberjust read from the first entry inErrors, populating that collection automatically lights up those property values.The broader picture here is that there are a few separate requests for changes to SqlException - issues #648 and #649 request SqlState and IsTransient support, issue #35 requests a public-facing constructor. Before adding new fields, I want to be sure that the underlying type serializes and deserializes correctly.
Issues
Fixes #1940.
Fixes #2150.
Testing
New unit test added to highlight regressions.
This new test uses BinaryFormatter, which is a bad practice in user code: it's known to be insecure when used with untrusted payloads. The alternative (DataContractSerializer) doesn't exactly mimic the original use case of .NET Framework Remoting though - DataContractSerializer requires a list of known types. I don't believe that the test introduces a security bug (we've got full control of the payloads we serialize and deserialize) but I'm not sure whether it'll be flagged as a risk.