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