When using ValueTuple
and dynamic object, I received this weird CS8133 error. I am passing dynamic object as input and taking ValueTuple as output. Why are they affecting each other.
public static (string, string) foo(dynamic input)
{
return ("", "");
}
public void foo_test()
{
dynamic input = new { a = "", b = "" };
(string v1, string v2) = foo(new { a = "", b = "" }); //compiles fine
(string v3, string v4) = foo(input); //CS8133 Cannot deconstruct dynamic objects
var result = foo(input); //compiles fine
}
Edit:
The error message is: CS8133 Cannot deconstruct dynamic objects
The C++ language provides mechanisms for mixing code that is compiled by compatible C and C++ compilers in the same program. You can experience varying degrees of success as you port such code to different platforms and compilers.
Just declare the C++ function extern "C" (in your C++ code) and call it (from your C or C++ code). For example: // C++ code: extern "C" void f(int);
Yes - C++ can use C libraries. Except of course that you're using the C++ version of cstdio . To use the C one you need to #include <stdio. h> .
See the feature spec:
The resolution is equivalent to typing
rhs.Deconstruct(out var x1, out var x2, ...);
with the appropriate number of parameters to deconstruct into. It is based on normal overload resolution. This implies that rhs cannot be dynamic and that none of the parameters of the Deconstruct method can be type arguments. ...
The part that is important is the var
.
In normal overload resolution, we can infer the type from the Deconstruct
methods that are discovered. But with dynamic method invocation, you cannot get compile-time type information, so the var
types are necessarily left un-inferred (ie. that's an error).
More generally, this is why you cannot use out var
on a dynamic invocation (what is the var
type of the out var local?).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With