C# Error CS8129 – No suitable ‘Deconstruct’ instance or extension method was found for type ‘{0}’, with {1} out parameters and a void return type.

C# Error

CS8129 – No suitable ‘Deconstruct’ instance or extension method was found for type ‘{0}’, with {1} out parameters and a void return type.

Reason for the Error & Solution

No suitable ‘Deconstruct’ instance or extension method was found for type, with out parameters and a void return type.

Example

The following sample generates CS8129:

// CS8129.cs (11,52)

class C
{
    static void Main()
    {
        long x;
        string y;
        (x, y) = new C();
    }

    public int Deconstruct(out int a, out string b)
    {
        a = 1;
        b = "hello";
        return 42;
    }
}

To correct this error

A valid Deconstruct method returns void and has two or more out parameters that match the type of a tuple that would be deconstructed. Implementing a valid Deconstruct method corrects this error:

    public void Deconstruct(out int a, out string b)
    {
        a = 1;
        b = "hello";
    }

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...