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