Skip to content

Commit

Permalink
Fix | Fix serialization issue with SqlException (.NET Core)
Browse files Browse the repository at this point in the history
Fixes #778
  • Loading branch information
cheenamalhotra committed Oct 30, 2020
1 parent b48de5d commit 3753e87
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Expand Up @@ -14,7 +14,6 @@ namespace Microsoft.Data.SqlClient
{
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlException.xml' path='docs/members[@name="SqlException"]/SqlException/*' />
[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";
Expand Down Expand Up @@ -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;
Expand Down
Expand Up @@ -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;

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 3753e87

Please sign in to comment.