Description
Given that static constructor invocation happens in particular scenarios controlled by the runtime, the Requires attribute is not allowed to be placed in the static constructor. Instead, the recommended way to suppress warnings coming from the static constructor is to annotate the class with Requires.
Tools like linker and analyzer display warnings to the user when the attribute is placed in the static constructor, NativeAOT needs to be able to present those warnings too.
Reproduction Steps
Add any of the Requires attributes to a static constructor
publicclassMyClass{// IL3056// IL2116// IL3004[RequiresDynamicCode("some message")][RequiresUnreferencedCode("some message")][RequiresAssemblyFiles("some message")publicstaticMyClass{}}
### Expectedbehavior
The commented warnings are generated
### Actual behavior
No warning is generated
### Regression?
_No response_
### Known Workarounds
_No response_
### Configuration
_No response_
### Other information
_No response_
Description
Given that static constructor invocation happens in particular scenarios controlled by the runtime, the Requires attribute is not allowed to be placed in the static constructor. Instead, the recommended way to suppress warnings coming from the static constructor is to annotate the class with Requires.
Tools like linker and analyzer display warnings to the user when the attribute is placed in the static constructor, NativeAOT needs to be able to present those warnings too.
Reproduction Steps
Add any of the Requires attributes to a static constructor