sonar-dotnet
sonar-dotnet copied to clipboard
New Rule Idea: UnsafeAccessorAttribute method should match the signature of its target
Related to C# 12 Zero-overhead member access.
Using UnsafeAccessorAttribute
on a extern
method with the parameters not matching the target results in a System.MissingMethodException Method not found
.
using System.Runtime.CompilerServices;
[UnsafeAccessor(UnsafeAccessorKind.Constructor)]
extern static UserData CallPrivateConstructor(int i); // Noncompliant: there is no constructor with this signature
extern static ref string GetName(UserData obj);
_ = CallPrivateConstructor(42);
class UserData
{
private UserData(string name) { }
}
Related new rule ideas on C# 12 Zero-overhead member access:
- https://github.com/SonarSource/sonar-dotnet/issues/8151
- https://github.com/SonarSource/sonar-dotnet/issues/8155