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

[rel/16.6] Fix null reference #2400

Merged
1 commit merged into from
Apr 14, 2020
Merged
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
31 changes: 18 additions & 13 deletions src/testhost.x86/TestHostTraceListener.cs
Expand Up @@ -31,21 +31,26 @@ public static void Setup()

EqtTrace.Verbose("TestPlatformTraceListener.Setup: Added test platform trace listener.");

#if NETCOREAPP2_1
try
// this is a netcoreapp2.1 only fix, but because we always compile against netcoreapp2.1
// and upgrade the executable as necessary this needs to be a runtime check and not a compile time
// check. This call returns ".NET Core 4.6.xxx" on netcore 2.1 and older, and ".NET Core 3.1.xxx"
// or the respective version on the newer runtimes
if (System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription.StartsWith(".NET Core 4.6"))
{
// workaround for netcoreapp2.1 where the trace listener api is not called when
// Debug.Assert fails. This method is internal, but the class is on purpose keeping the
// callback settable so tests can set the callback
var field = typeof(Debug).GetField("s_ShowDialog", BindingFlags.Static | BindingFlags.NonPublic);
var value = field.GetValue(null);
field.SetValue(null, (Action<string, string, string, string>)ShowDialog);
}
catch (Exception ex)
{
EqtTrace.Error("TestPlatformTraceListener.Setup: Failed to replace inner callback to ShowDialog in Debug.Assert. Calls to Debug.Assert with crash the test host process. {0}", ex);
try
{
// workaround for netcoreapp2.1 where the trace listener api is not called when
// Debug.Assert fails. This method is internal, but the class is on purpose keeping the
// callback settable so tests can set the callback
var field = typeof(Debug).GetField("s_ShowDialog", BindingFlags.Static | BindingFlags.NonPublic);
var value = field.GetValue(null);
field.SetValue(null, (Action<string, string, string, string>)ShowDialog);
}
catch (Exception ex)
{
EqtTrace.Error("TestPlatformTraceListener.Setup: Failed to replace inner callback to ShowDialog in Debug.Assert. Calls to Debug.Assert with crash the test host process. {0}", ex);
}
}
#endif
}

public override void Fail(string message)
Expand Down