Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix | Fix serialization issue with SqlException (.NET Core) #780

Merged
merged 1 commit into from Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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")]
JRahnama marked this conversation as resolved.
Show resolved Hide resolved
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