-
Notifications
You must be signed in to change notification settings - Fork 292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SqlException fails to deserialize via BinaryFormatter #778
Comments
I noticed that BinaryFormatter is deprecated in .NET 5.0 and beyond, but I thought it best to err on the side of reporting the issue. In my particular case, this is not a huge issue, as the RPC call was returning an exception anyway. It's merely unfortunate that the exception encountered by the caller is a serialization-related exception rather than the exception returned from the RPC call. However, the back-end includes logging as well, so the original exception information is not entirely lost. |
Hi @danlyons-softek Thanks for reporting this issue. |
Describe the bug
In one project I work on, RPC is done via RabbitMQ, serializing request/reply data with BinaryFormatter. Recently, I ran across an error when deserializing SqlExceptions raised on the back-end.
There appear to be two distinct exceptions raised:
TargetInvokcationException with an inner exception of InvalidCastException when the deserialized exception includes SqlException as its inner exception:
SerializationException when the deserialized exception is SqlException itself:
To reproduce
Attached is a minimal reproduction of the issue. TestDir has functions to create a test table, insert a value, and drop the test table. Program calls into TestDir with two inserts of the same value to trigger a SqlException for a primary key violation, then serializes and deserializes the exception with BinaryFormatter.
testdbexception.zip
Expected behavior
I would expect the deserialization to complete successfully, particularly given SqlException is marked as serializable, implements ISerializable, and serializes without issue.
Further technical details
Microsoft.Data.SqlClient version: latest (2.0.1)
.NET target: Core 3.1
SQL Server version: SQL Server 2016
Operating system: Windows 10 (dev machine), Server 2016 (production machine)
The text was updated successfully, but these errors were encountered: