C# Error
CS8812 – Cannot convert &method group ‘{0}’ to non-function pointer type ‘{1}’.
Reason for the Error & Solution
Cannot convert &method group to non-function pointer type.
Example
The following sample generates CS8812:
// CS8812.cs (6,22)
unsafe class C
{
static void M()
{
void* ptr1 = &M;
}
}
The address of an expression (e.g., &M
) has no type and thus cannot be assigned to a non-function pointer variable.
To correct this error
Explicitly convert the expression to the required type (e.g., a void
delegate
):
unsafe class C
{
static void M()
{
void* ptr1 = (delegate*<void>)&M;
}
}