Skip to content

Aot Analyzer shouldn't warn when passing a const string to RequiresDynamicCode applied to Types #84433

Closed
@eerhardt

Description

@eerhardt

If I have a class like:

    [RequiresDynamicCode(RequiresDynamicCodeMessage)]
    public class XmlDsigXsltTransform : Transform
    {
        internal const string RequiresDynamicCodeMessage = "XmlDsigXsltTransform uses XslCompiledTransform which requires dynamic code.";

I am getting a warning by the analyzer:

XmlDsigXsltTransform.cs(12,26): error IL3050: Using member 'System.Security.Cryptography.Xml.XmlDsigXsltTransform.RequiresDynamicCodeMessage' which has RequiresDynamicCodeAttribute' can break functionality when AOT compiling. XmlDsigXsltTransform uses XslCompiledTransform which equires dynamic code. [C:\git\runtime2\src\libraries\System.Security.Cryptography.Xml\src\System.Security.Cryptography.Xml.csproj::TargetFramework=net8.0]

Similarly, if I reference the const string from another RequiresDynamicCode attribute applied to a class:

    [RequiresDynamicCode(XmlDsigXsltTransform.RequiresDynamicCodeMessage)]
    public class SignedInfo : ICollection
    {

produces:

SignedInfo.cs(10,26): error IL3050: Using member  'System.Security.Cryptography.Xml.XmlDsigXsltTransform.RequiresDynamicCodeMessage' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. XmlDsigXsltTransform uses XslCompiledTransform which requires dynamic code. [C:\git\runtime2\src\libraries\System.Security.Cryptography.Xml\src\System.Security.Cryptography.Xml.csproj::TargetFramework=net8.0]

But if I reference the const string from a RequiresDynamicCode attribute applied to a method, it doesn't warn:

        [RequiresDynamicCode(XmlDsigXsltTransform.RequiresDynamicCodeMessage)]
        internal void LoadXml(XmlElement value)
        {

I am declaring a RequiresDynamicCode attribute, the parameter I pass to the ctor of the attribute should also be considered as being in a "RequiresDynamicCode" scope - since by definition, I'm inside RequiresDynamicCode.

@vitek-karas @sbomer

Metadata

Metadata

Assignees

Labels

area-Tools-ILLink.NET linker development as well as trimming analyzers

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions