From 4d83e375dee051d66dc573c0b24b0568eb653b0a Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Thu, 9 Sep 2021 13:00:03 -0700 Subject: [PATCH] Fix null reference exception in library mode (#1546) --- .../StartupCode/StartupCodeHelpers.Reflection.cs | 4 ++-- .../src/System/Reflection/Assembly.CoreRT.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/StartupCode/StartupCodeHelpers.Reflection.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/StartupCode/StartupCodeHelpers.Reflection.cs index 39aca56ad956..7fc2641f43ce 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/StartupCode/StartupCodeHelpers.Reflection.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/StartupCode/StartupCodeHelpers.Reflection.cs @@ -16,9 +16,9 @@ internal static void InitializeEntryAssembly(RuntimeTypeHandle entryAssemblyType s_entryAssemblyType = entryAssemblyType; } - internal static Assembly GetEntryAssembly() + internal static Assembly? GetEntryAssembly() { - return Type.GetTypeFromHandle(s_entryAssemblyType).Assembly; + return Type.GetTypeFromHandle(s_entryAssemblyType)?.Assembly; } } } diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Assembly.CoreRT.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Assembly.CoreRT.cs index c258a62962a6..67332c612fdd 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Assembly.CoreRT.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Assembly.CoreRT.cs @@ -12,7 +12,7 @@ namespace System.Reflection { public abstract partial class Assembly : ICustomAttributeProvider, ISerializable { - private static Assembly GetEntryAssemblyInternal() => Internal.Runtime.CompilerHelpers.StartupCodeHelpers.GetEntryAssembly(); + private static Assembly? GetEntryAssemblyInternal() => Internal.Runtime.CompilerHelpers.StartupCodeHelpers.GetEntryAssembly(); [System.Runtime.CompilerServices.Intrinsic] public static Assembly GetExecutingAssembly() { throw NotImplemented.ByDesign; } //Implemented by toolchain.