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

Use a serialization compatible marker #73851

Merged
merged 3 commits into from
Jun 12, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,10 @@ public static bool ReportAndCatchUnlessCanceled(Exception exception, Cancellatio

#endif

private static readonly object s_reportedMarker = new();
// We use a Guid for the marker because it is used as a key in an exceptions Data dictionary, so we must make sure
// it's serializable if the exception crosses an RPC boundary. In particular System.Text.Json doesn't like plain
// object dictionary keys.
private static readonly object s_reportedMarker = Guid.NewGuid();
davidwengier marked this conversation as resolved.
Show resolved Hide resolved

// Do not allow this method to be inlined. That way when we have a dump we can see this frame in the stack and
// can examine things like s_reportedExceptionMessage. Without this, it's a lot tricker as FatalError is linked
Expand Down
14 changes: 14 additions & 0 deletions src/Workspaces/CoreTest/UtilityTest/ExceptionHelpersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#nullable disable

using System;
using System.Text.Json;
using Microsoft.CodeAnalysis.ErrorReporting;
using Roslyn.Test.Utilities;
using Roslyn.Utilities;
Expand Down Expand Up @@ -55,5 +56,18 @@ void a()

Assert.True(false, "Should have returned in the catch block before this point.");
}

[Fact]
public void ErrorReporting_SerializesException()
{
FatalError.SetHandlers(delegate { }, delegate { });

var e = new Exception("Hello");
FatalError.ReportNonFatalError(e);

Assert.NotEmpty(e.Data);
Assert.NotNull(JsonSerializer.Serialize(e));
Assert.NotNull(Newtonsoft.Json.JsonConvert.SerializeObject(e));
}
}
}
Loading