C# Error CS8812 – Cannot convert &method group ‘{0}’ to non-function pointer type ‘{1}’.

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;
    }
}

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...