Open
Description
The UnsafeAccessorAttribute
feature has some non-obvious issues in some scenarios. The most recent example is captured in #91740.
Example:
using System.Runtime.CompilerServices;
class Program
{
static void Main()
{
// Crashes at runtime with System.MissingMethodException:
// Method not found: 'System.Object.<Main>g__MemberwiseClone|0_0'.
_ = MemberwiseClone(new object());
[UnsafeAccessor(UnsafeAccessorKind.Method)] // Analyzer should warn when applied to local function without defining "Name" property.
static extern object MemberwiseClone(object obj);
}
}
Additional cases for analyzer to consider: #91740 (comment)