From efa25b253d5c5456cc6fa1fec95271a8c6c7ee02 Mon Sep 17 00:00:00 2001 From: Theodore Tsirpanis Date: Tue, 12 Jul 2022 01:04:49 +0300 Subject: [PATCH] Mark `Assembly.GetCallingAssembly` with `[RequiresDynamicCode]`. --- .../src/System/Reflection/Assembly.CoreCLR.cs | 2 ++ .../src/System/Reflection/Assembly.NativeAot.cs | 4 +++- src/libraries/System.Runtime/ref/System.Runtime.cs | 1 + .../src/System/Reflection/Assembly.Mono.cs | 2 ++ 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Assembly.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Assembly.CoreCLR.cs index 970684d6330db..5cc72842e017a 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Assembly.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Assembly.CoreCLR.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -71,6 +72,7 @@ public static Assembly GetExecutingAssembly() } [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod + [RequiresDynamicCode("Assembly.GetCallingAssembly is not supported in AOT environments.")] public static Assembly GetCallingAssembly() { // LookForMyCallersCaller is not guaranteed to return the correct stack frame diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Assembly.NativeAot.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Assembly.NativeAot.cs index fd1e3e899fd7a..29d97390e27f7 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Assembly.NativeAot.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Assembly.NativeAot.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Configuration.Assemblies; +using System.Diagnostics.CodeAnalysis; using System.Runtime.Serialization; using System.IO; @@ -16,7 +17,8 @@ public abstract partial class Assembly : ICustomAttributeProvider, ISerializable [System.Runtime.CompilerServices.Intrinsic] public static Assembly GetExecutingAssembly() { throw NotImplemented.ByDesign; } //Implemented by toolchain. - + + [RequiresDynamicCode("Assembly.GetCallingAssembly is not supported in AOT environments.")] public static Assembly GetCallingAssembly() { if (AppContext.TryGetSwitch("Switch.System.Reflection.Assembly.SimulatedCallingAssembly", out bool isSimulated) && isSimulated) diff --git a/src/libraries/System.Runtime/ref/System.Runtime.cs b/src/libraries/System.Runtime/ref/System.Runtime.cs index 07abb8a23199f..7dbfef6240064 100644 --- a/src/libraries/System.Runtime/ref/System.Runtime.cs +++ b/src/libraries/System.Runtime/ref/System.Runtime.cs @@ -10731,6 +10731,7 @@ public virtual event System.Reflection.ModuleResolveEventHandler? ModuleResolve public static string CreateQualifiedName(string? assemblyName, string? typeName) { throw null; } public override bool Equals(object? o) { throw null; } public static System.Reflection.Assembly? GetAssembly(System.Type type) { throw null; } + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("Assembly.GetCallingAssembly is not supported in AOT environments.")] public static System.Reflection.Assembly GetCallingAssembly() { throw null; } public virtual object[] GetCustomAttributes(bool inherit) { throw null; } public virtual object[] GetCustomAttributes(System.Type attributeType, bool inherit) { throw null; } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Assembly.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Assembly.Mono.cs index ba531f8083f1e..826d4f35d4c85 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Assembly.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Assembly.Mono.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -42,6 +43,7 @@ public static Assembly GetExecutingAssembly() [MethodImplAttribute(MethodImplOptions.InternalCall)] internal static extern RuntimeAssembly GetExecutingAssembly(ref StackCrawlMark stackMark); + [RequiresDynamicCode("Assembly.GetCallingAssembly is not supported in AOT environments.")] [MethodImplAttribute(MethodImplOptions.InternalCall)] public static extern Assembly GetCallingAssembly();