From 2482f612f6ad0248d94bb222aedc450e0915a98e Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Wed, 26 Aug 2020 08:42:04 +0200 Subject: [PATCH 1/2] Fix null check in S.Diagnostics.Contract regressed by nullability annotations --- .../src/System/Diagnostics/Contracts/Contracts.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Contracts/Contracts.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Contracts/Contracts.cs index 9840efd50cd1e9..493fae9854380e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Contracts/Contracts.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Contracts/Contracts.cs @@ -628,7 +628,8 @@ private static void AssertMustUseRewriter(ContractFailureKind kind, string contr Assembly? probablyNotRewritten = null; for (int i = 0; i < stack.FrameCount; i++) { - Assembly? caller = stack.GetFrame(i)!.GetMethod()?.DeclaringType!.Assembly; + MethodBase stackMethod = stack.GetFrame(i)!.GetMethod(); + Assembly? caller = (stackMethod != null) ? stackMethod.DeclaringType!.Assembly : null; if (caller != null && caller != thisAssembly) { probablyNotRewritten = caller; From c9574bdff240fb4c30b55e2c81a20c4fdf6a50fe Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Wed, 26 Aug 2020 15:04:39 +0200 Subject: [PATCH 2/2] fix product per Jan's recommendation --- .../src/System/Diagnostics/Contracts/Contracts.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Contracts/Contracts.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Contracts/Contracts.cs index 493fae9854380e..49445f16b2d071 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Contracts/Contracts.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Contracts/Contracts.cs @@ -628,8 +628,7 @@ private static void AssertMustUseRewriter(ContractFailureKind kind, string contr Assembly? probablyNotRewritten = null; for (int i = 0; i < stack.FrameCount; i++) { - MethodBase stackMethod = stack.GetFrame(i)!.GetMethod(); - Assembly? caller = (stackMethod != null) ? stackMethod.DeclaringType!.Assembly : null; + Assembly? caller = stack.GetFrame(i)!.GetMethod()?.DeclaringType?.Assembly; if (caller != null && caller != thisAssembly) { probablyNotRewritten = caller;