Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Commit

Permalink
Debug: Do not trigger string cctor in Debug.Assert if it's unnecessary
Browse files Browse the repository at this point in the history
This patch fixes crashes due to ClassConstructorRunner.EnsureClassConstructorRun
is called before ClassConstructorRunner.Initialize.
  • Loading branch information
Konstantin Baladurin committed Dec 3, 2018
1 parent f9a0aae commit 61683d6
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/System.Private.CoreLib/shared/System/Diagnostics/Debug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,23 @@ public static void Print(string format, params object[] args)
[System.Diagnostics.Conditional("DEBUG")]
public static void Assert(bool condition)
{
Assert(condition, string.Empty, string.Empty);
// Do not trigger string cctor if it's unnecessary otherwise we can call ClassConstructorRunner.EnsureClassConstructorRun
// before ClassConstructorRunner.Initialize is called.
if (!condition)
{
Assert(condition, string.Empty, string.Empty);
}
}

[System.Diagnostics.Conditional("DEBUG")]
public static void Assert(bool condition, string message)
{
Assert(condition, message, string.Empty);
// Do not trigger string cctor if it's unnecessary otherwise we can call ClassConstructorRunner.EnsureClassConstructorRun
// before ClassConstructorRunner.Initialize is called.
if (!condition)
{
Assert(condition, message, string.Empty);
}
}

[System.Diagnostics.Conditional("DEBUG")]
Expand Down

0 comments on commit 61683d6

Please sign in to comment.