Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark Assembly.GetCallingAssembly with [RequiresDynamicCode]. #71973

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -17,6 +18,7 @@ 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)
Expand Down Expand Up @@ -54,5 +56,5 @@ public static Assembly LoadWithPartialName(string partialName)
return null;
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ internal ErrObject() { }
public string Source { get { throw null; } set { } }
public void Clear() { }
public System.Exception? GetException() { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("ErrObject.Raise is not supported in AOT environments. Throw exceptions with the Throw keyword instead.")]
public void Raise(int Number, object? Source = null, object? Description = null, object? HelpFile = null, object? HelpContext = null) { }
}
[System.FlagsAttribute]
Expand All @@ -329,6 +330,7 @@ public enum FileAttribute
Directory = 16,
Archive = 32,
}
[System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The FileSystem module is not supported in AOT environments. Use members of the System.IO namespace instead.")]
[Microsoft.VisualBasic.CompilerServices.StandardModuleAttribute]
public sealed partial class FileSystem
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many but not all APIs of this class use GetCallingAssembly (some did call it only in debug asserts) but I didn't bother and marked the whole class. This class is very outdated either way.

{
Expand Down Expand Up @@ -1146,6 +1148,7 @@ public sealed partial class ProjectData
internal ProjectData() { }
public static void ClearProjectError() { }
public static System.Exception CreateProjectError(int hr) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("ProjectData.EndApp is not supported in AOT environments. Use System.Environment.Exit(0) instead.")]
public static void EndApp() { }
public static void SetProjectError(System.Exception? ex) { }
public static void SetProjectError(System.Exception? ex, int lErl) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
' The .NET Foundation licenses this file to you under the MIT license.

Imports System
Imports System.Diagnostics.CodeAnalysis

Namespace Global.Microsoft.VisualBasic.CompilerServices

Expand Down Expand Up @@ -177,6 +178,7 @@ Namespace Global.Microsoft.VisualBasic.CompilerServices
Err.Clear()
End Sub

<RequiresDynamicCode("ProjectData.EndApp is not supported in AOT environments. Use System.Environment.Exit(0) instead.")>
Public Shared Sub EndApp()
FileSystem.CloseAllFiles(System.Reflection.Assembly.GetCallingAssembly())
System.Environment.Exit(0) 'System.Environment.Exit will cause finalizers to be run at shutdown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Imports Microsoft.VisualBasic.CompilerServices
Imports Microsoft.VisualBasic.CompilerServices.Utils

Imports System
Imports System.Diagnostics.CodeAnalysis
Imports System.Runtime.InteropServices

Namespace Microsoft.VisualBasic
Expand Down Expand Up @@ -269,6 +270,7 @@ Namespace Microsoft.VisualBasic
''' <param name="Description">If not supplied, we try to look one up based on the error code being raised</param>
''' <param name="HelpFile"></param>
''' <param name="HelpContext"></param>
<RequiresDynamicCode("ErrObject.Raise is not supported in AOT environments. Throw exceptions with the Throw keyword instead.")>
Public Sub Raise(ByVal Number As Integer,
Optional ByVal Source As Object = Nothing,
Optional ByVal Description As Object = Nothing,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Imports Microsoft.VisualBasic.CompilerServices.Utils

Namespace Microsoft.VisualBasic

<RequiresDynamicCode("The FileSystem module is not supported in AOT environments. Use members of the System.IO namespace instead.")>
Public Module FileSystem

Private Const ERROR_FILE_NOT_FOUND As Integer = 2
Expand Down
1 change: 1 addition & 0 deletions src/libraries/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();

Expand Down