C# Error CS8131 – Deconstruct assignment requires an expression with a type on the right-hand-side.

C# Error

CS8131 – Deconstruct assignment requires an expression with a type on the right-hand-side.

Reason for the Error & Solution

Deconstruct assignment requires an expression with a type on the right-hand-side.

Example

The following sample generates CS8131:

// CS8131.cs (5,24)
class Program
{
    static void Main()
    {
        var (x2, y2) = () => { };
    }
}

The compiler cannot convert a delegate (Action) to a two-element tuple, resulting in CS8131.

To correct this error

To assign a value to a tuple, ensure the right-hand-side expression is the same type of tuple as that on the left-hand-side:

    static void Main()
    {
        var (x2, y2) = (1, 2);
    }

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