BC36548: Cannot convert anonymous type to an expression tree because a property of the type is used to initialize another property
The compiler does not accept conversion of an anonymous type to an expression tree when one property of the anonymous type is used to initialize another property of the anonymous type. For example, in the following code, Prop1
is declared in the initialization list and then used as the initial value for Prop2
.
Error ID: BC36548
Example
Module M2
Sub ExpressionExample(Of T)(x As Expressions.Expression(Of Func(Of T)))
End Sub
Sub Main()
' The following line causes the error.
ExpressionExample(Function() New With {.Prop1 = 2, .Prop2 = .Prop1})
End Sub
End Module
To correct this error
Assign the initial value for Prop1
to a local variable. Assign that variable to both Prop1
and Prop2
, as shown in the following code:
Sub Main()
Dim temp = 2
ExpressionExample(Function() New With {.Prop1 = temp, .Prop2 = temp})
End Sub
See also
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for