Description
This analyzer detects when[AotUnsafe] is applied to code that doesn’t actually use any AOT-incompatible patterns. This helps prevent over-annotation where developers mark code as unsafe “just to be safe” when it’s actually AOT-compatible.
The analyzer checks for these AOT-incompatible patterns:
- Calls to methods with
[RequiresDynamicCode] - Calls to other
[AotUnsafe]methods - Reflection APIs:
Type.GetMethod,Type.GetProperty,PropertyInfo.GetValue,Activator.CreateInstance, etc. Reflection.Emitnamespace usagedynamickeyword usage
Bad Code
Good Code
Properties
- Category: AOT Testing
- Severity: Warning (Suggestion)
- Enabled by default: True
- Code fix available: False
Configuration
Detected Patterns
The analyzer recognizes these as legitimate reasons for[AotUnsafe]:
See Also
- AL0052 - AotSafe code must not call AotUnsafe code
- AL0044 - AotSafe code must not call RequiresDynamicCode methods
- AotUnsafe attribute documentation
