SqlException.Errors serialization #1826
KalleOlaviNiemitalo
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The SqlException.GetObjectData method does not serialize the SqlException.Errors property (SqlException._errors field) as such; instead, it converts each SqlError instance to a string and adds the string to Exception.Data. The serialization constructor does not parse the Exception.Data strings back to SqlError instances and so properties such as SqlException.Number will lose their values in the deserialized exception.
There is a comment about "non-serializable type", but it seems to be out of date. Perhaps SqlException could now be changed to serialize its Errors collection in the usual way, instead of resorting to Exception.Data.
SqlClient/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlException.cs
Lines 53 to 69 in 711b72c
The SqlErrorCollection and SqlError types are serializable:
SqlClient/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlErrorCollection.cs
Lines 13 to 14 in 711b72c
SqlClient/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlError.cs
Lines 10 to 11 in 711b72c
The comment came from #166. The types have been serializable on .NET Core since #1322, and were already serializable on .NET Framework before that.
Beta Was this translation helpful? Give feedback.
All reactions