From 3753e87ea39f02fe7bde7420f95497ef7c3a5f80 Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Thu, 29 Oct 2020 23:38:24 -0700 Subject: [PATCH] Fix | Fix serialization issue with SqlException (.NET Core) Fixes #778 --- .../Microsoft/Data/SqlClient/SqlException.cs | 3 +- .../SQL/ExceptionTest/ExceptionTest.cs | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlException.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlException.cs index 5f4e952ec8..2c50c5a3d7 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlException.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlException.cs @@ -14,7 +14,6 @@ namespace Microsoft.Data.SqlClient { /// [Serializable] - [System.Runtime.CompilerServices.TypeForwardedFrom("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public sealed partial class SqlException : System.Data.Common.DbException { private const string OriginalClientConnectionIdKey = "OriginalClientConnectionId"; @@ -214,7 +213,7 @@ internal static SqlException CreateException(SqlErrorCollection errorCollection, } exception.Data.Add("HelpLink.EvtSrc", "MSSQLServer"); exception.Data.Add("HelpLink.EvtID", errorCollection[0].Number.ToString(CultureInfo.InvariantCulture)); - exception.Data.Add("HelpLink.BaseHelpUrl", "http://go.microsoft.com/fwlink"); + exception.Data.Add("HelpLink.BaseHelpUrl", "https://go.microsoft.com/fwlink"); exception.Data.Add("HelpLink.LinkId", "20476"); return exception; diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ExceptionTest/ExceptionTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ExceptionTest/ExceptionTest.cs index 150e256435..6038df2c97 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ExceptionTest/ExceptionTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ExceptionTest/ExceptionTest.cs @@ -6,6 +6,8 @@ using System.Collections; using System.Collections.Generic; using System.Globalization; +using System.IO; +using System.Runtime.Serialization.Formatters.Binary; using System.Threading.Tasks; using Xunit; @@ -65,6 +67,32 @@ private static bool EmployeesTableHasFullTextIndex() } } + [Fact] + public static void SqlExcpetionSerializationTest() + { + var formatter = new BinaryFormatter(); + try + { + GenerateConnectionException("Server=nonexistingserver"); + } + catch (SqlException e) + { + using (var stream = new MemoryStream()) + { + try + { + formatter.Serialize(stream, e); + stream.Position = 0; + var e2 = (SqlException)formatter.Deserialize(stream); + } + catch (Exception ex) + { + Assert.False(true, $"Unexpected Exception occurred: {ex.Message}"); + } + } + } + } + // TODO Synapse: Remove dependency from Northwind database. [ConditionalFact(nameof(EmployeesTableHasFullTextIndex))] public static void WarningsBeforeRowsTest()