Fix null check in S.Diagnostics.Contract regressed by nullability annotations (#41382)
authorKrzysztof Wicher <mordotymoja@gmail.com>
Thu, 27 Aug 2020 18:00:42 +0000 (20:00 +0200)
committerGitHub <noreply@github.com>
Thu, 27 Aug 2020 18:00:42 +0000 (20:00 +0200)
* Fix null check in S.Diagnostics.Contract regressed by nullability annotations

* fix product per Jan's recommendation

src/libraries/System.Private.CoreLib/src/System/Diagnostics/Contracts/Contracts.cs

index 9840efd..49445f1 100644 (file)
@@ -628,7 +628,7 @@ namespace System.Diagnostics.Contracts
             Assembly? probablyNotRewritten = null;
             for (int i = 0; i < stack.FrameCount; i++)
             {
-                Assembly? caller = stack.GetFrame(i)!.GetMethod()?.DeclaringType!.Assembly;
+                Assembly? caller = stack.GetFrame(i)!.GetMethod()?.DeclaringType?.Assembly;
                 if (caller != null && caller != thisAssembly)
                 {
                     probablyNotRewritten = caller;