Skip to content

Commit

Permalink
Fix | Fix serialization issue with SqlException (.NET Core) (#780)
Browse files Browse the repository at this point in the history
Fixes #778
  • Loading branch information
cheenamalhotra committed Nov 3, 2020
1 parent ab9fbb7 commit a7545de
Show file tree
Hide file tree
Showing 2 changed files with 25 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 @@ -3,6 +3,8 @@
// See the LICENSE file in the project root for more information.

using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using Newtonsoft.Json;
using Xunit;

Expand Down Expand Up @@ -31,6 +33,28 @@ public void SerializationTest()
Assert.Equal(e.StackTrace, sqlEx.StackTrace);
}


[Fact]
[ActiveIssue("12161", TestPlatforms.AnyUnix)]
public static void SqlExcpetionSerializationTest()
{
var formatter = new BinaryFormatter();
SqlException e = CreateException();
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}");
}
}
}

[Fact]
public void JSONSerializationTest()
{
Expand Down

0 comments on commit a7545de

Please sign in to comment.