score:2

Accepted answer

Your problem has nothing to do with expression trees (which would be easier to spot if you bothered to include the error you're getting).

You have Option Infer Off and Option Strict Off and the following code:

Dim getter = getterLambda.Compile()

Return getter()

which throws MissingMemberException:

No default member found for type 'Func(Of Object)'.

The problem is that () is here interpreted as invoking the default member and not invoking a delegate, because getter is typed as Object. To work around that, you can specify the type of the variable:

Dim getter As Func(Of Object) = getterLambda.Compile()

Return getter()

or you can use more verbose syntax for invoking a delegate:

Dim getter = getterLambda.Compile()

Return getter.Invoke()

Related Query

More Query from same tag