diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/RequiresDynamicCodeAttribute.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/RequiresDynamicCodeAttribute.cs index a067002e9f9fc..157b06404580d 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/RequiresDynamicCodeAttribute.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/RequiresDynamicCodeAttribute.cs @@ -10,7 +10,7 @@ namespace System.Diagnostics.CodeAnalysis /// /// This allows tools to understand which methods are unsafe to call when compiling ahead of time. /// - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor, Inherited = false)] + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class, Inherited = false)] public sealed class RequiresDynamicCodeAttribute : Attribute { /// diff --git a/src/libraries/System.Runtime/ref/System.Runtime.cs b/src/libraries/System.Runtime/ref/System.Runtime.cs index b3ae854842fc3..bf0c090eda474 100644 --- a/src/libraries/System.Runtime/ref/System.Runtime.cs +++ b/src/libraries/System.Runtime/ref/System.Runtime.cs @@ -7458,7 +7458,7 @@ public RequiresAssemblyFilesAttribute(string message) { } public string? Message { get { throw null; } } public string? Url { get { throw null; } set { } } } - [System.AttributeUsageAttribute(System.AttributeTargets.Constructor | System.AttributeTargets.Method, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Constructor | System.AttributeTargets.Method | AttributeTargets.Class, Inherited=false)] public sealed partial class RequiresDynamicCodeAttribute : System.Attribute { public RequiresDynamicCodeAttribute(string message) { } diff --git a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Regex.cs b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Regex.cs index 07b435a930967..a9640fe41250f 100644 --- a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Regex.cs +++ b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Regex.cs @@ -74,6 +74,8 @@ internal Regex(string pattern, CultureInfo? culture) // if no options are ever used. } + [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", + Justification = "Native AOT does not use compiled Regex")] internal Regex(string pattern, RegexOptions options, TimeSpan matchTimeout, CultureInfo? culture) { // Validate arguments. @@ -201,6 +203,7 @@ protected IDictionary? CapNames /// Regex constructor, we don't load RegexCompiler and its reflection classes when /// instantiating a non-compiled regex. /// + [RequiresDynamicCode("The native code for Regex compilation might not be available at runtime.")] [MethodImpl(MethodImplOptions.NoInlining)] private static RegexRunnerFactory? Compile(string pattern, RegexTree regexTree, RegexOptions options, bool hasTimeout) => RegexCompiler.Compile(pattern, regexTree, options, hasTimeout); diff --git a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCompiler.cs b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCompiler.cs index 4e4ead63ba934..bb67b8131e19b 100644 --- a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCompiler.cs +++ b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCompiler.cs @@ -15,8 +15,7 @@ namespace System.Text.RegularExpressions /// /// RegexCompiler translates a block of RegexCode to MSIL, and creates a subclass of the RegexRunner type. /// - [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", - Justification = "Native AOT does not use compiled Regex")] + [RequiresDynamicCode("The native code for Regex compilation might not be available at runtime.")] internal abstract class RegexCompiler { private static readonly FieldInfo s_runtextstartField = RegexRunnerField("runtextstart"); diff --git a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexLWCGCompiler.cs b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexLWCGCompiler.cs index e246c1702315d..d71c1edcd85a5 100644 --- a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexLWCGCompiler.cs +++ b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexLWCGCompiler.cs @@ -31,6 +31,7 @@ internal sealed class RegexLWCGCompiler : RegexCompiler private static int s_regexCount; /// The top-level driver. Initializes everything then calls the Generate* methods. + [RequiresDynamicCode("The native code for Regex compilation might not be available at runtime.")] public RegexRunnerFactory? FactoryInstanceFromCode(string pattern, RegexTree regexTree, RegexOptions options, bool hasTimeout) { if (!regexTree.Root.SupportsCompilation(out _)) @@ -66,8 +67,7 @@ internal sealed class RegexLWCGCompiler : RegexCompiler } /// Begins the definition of a new method (no args) with a specified return value. - [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", - Justification = "Native AOT does not use compiled Regex")] + [RequiresDynamicCode("The native code for Regex compilation might not be available at runtime.")] private DynamicMethod DefineDynamicMethod(string methname, Type? returntype, Type hostType, Type[] paramTypes) { // We're claiming that these are static methods, but really they are instance methods.