Skip to content

Commit a7545de

Browse files
Fix | Fix serialization issue with SqlException (.NET Core) (#780)
Fixes #778
1 parent ab9fbb7 commit a7545de

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlException.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ namespace Microsoft.Data.SqlClient
1414
{
1515
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlException.xml' path='docs/members[@name="SqlException"]/SqlException/*' />
1616
[Serializable]
17-
[System.Runtime.CompilerServices.TypeForwardedFrom("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
1817
public sealed partial class SqlException : System.Data.Common.DbException
1918
{
2019
private const string OriginalClientConnectionIdKey = "OriginalClientConnectionId";
@@ -214,7 +213,7 @@ internal static SqlException CreateException(SqlErrorCollection errorCollection,
214213
}
215214
exception.Data.Add("HelpLink.EvtSrc", "MSSQLServer");
216215
exception.Data.Add("HelpLink.EvtID", errorCollection[0].Number.ToString(CultureInfo.InvariantCulture));
217-
exception.Data.Add("HelpLink.BaseHelpUrl", "http://go.microsoft.com/fwlink");
216+
exception.Data.Add("HelpLink.BaseHelpUrl", "https://go.microsoft.com/fwlink");
218217
exception.Data.Add("HelpLink.LinkId", "20476");
219218

220219
return exception;

src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlExceptionTest.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6+
using System.IO;
7+
using System.Runtime.Serialization.Formatters.Binary;
68
using Newtonsoft.Json;
79
using Xunit;
810

@@ -31,6 +33,28 @@ public void SerializationTest()
3133
Assert.Equal(e.StackTrace, sqlEx.StackTrace);
3234
}
3335

36+
37+
[Fact]
38+
[ActiveIssue("12161", TestPlatforms.AnyUnix)]
39+
public static void SqlExcpetionSerializationTest()
40+
{
41+
var formatter = new BinaryFormatter();
42+
SqlException e = CreateException();
43+
using (var stream = new MemoryStream())
44+
{
45+
try
46+
{
47+
formatter.Serialize(stream, e);
48+
stream.Position = 0;
49+
var e2 = (SqlException)formatter.Deserialize(stream);
50+
}
51+
catch (Exception ex)
52+
{
53+
Assert.False(true, $"Unexpected Exception occurred: {ex.Message}");
54+
}
55+
}
56+
}
57+
3458
[Fact]
3559
public void JSONSerializationTest()
3660
{

0 commit comments

Comments
 (0)