Error message when you pass a lambda expression to a late-bound method call that is nested inside another late-bound method call in Visual Basic 2008: “Expression does not produce a value”

Consider the following scenario. In Microsoft Visual Basic 2008, you pass a lambda expression as a parameter to a late-bound method call. The late-bound method call is nested inside another late-bound method call. In this scenario, you receive the following error message:

Expression does not produce a value

RESOLUTION

To resolve this problem, use one of the following methods.

Method 1

Make the first method call an early bound method call by specifying the type for the first object.

Method 2

Assign the lambda expression to a separate variable before you pass the lambda expression to the late-bound method call.

For example, the following code causes the error message that is mentioned in the “Symptoms” section.

Dim variable1, variable2 As Object

variable1.LateBoundCall(variable2.LateBoundCall(Function(a As Integer) a))

To resolve this problem, change this code as follows.

Dim variable1, variable2 As Object

Dim delegateName As Func(Of Integer, Integer) = Function(a As Integer) a
variable1.LateBoundCall(variable2.LateBoundCall(delegateName))

MORE INFORMATION

Steps to reproduce the problem

1. In Microsoft Visual Studio 2008, click New, and then click Project.
2. Click Visual Basic, click Console Application, type ConsoleApplication1 in the Name box, and then click OK.
3. In Solution Explorer, right-click ConsoleApplication1, click Add, and then click New Item.
4. Click Class, type SampleClass.vb in the Name box, and then click OK.
5. In the SampleClass.vb file, replace the existing code by using the following code.

Public Class SampleClass
        Sub LateBoundCall(ByVal x As Object)
        End Sub
End Class
6. In the Module1.vb file, add the following code to the Sub Main procedure.

Dim variable1, variable2 As Object

variable1.LateBoundCall(variable2.LateBoundCall(Function(a As Integer) a))

APPLIES TO
    Microsoft Visual Studio 2008 Standard Edition
      Microsoft Visual Studio 2008 Professional Edition
        Microsoft Visual Studio 2008 Academic Edition
          Microsoft Visual Web Developer 2008 Express Edition
            Microsoft Visual Basic 2008 Express Edition

            ——————————————–

            Microsoft Knowledge Base Article

            This article contents is Microsoft Copyrighted material.
            Microsoft Corporation. All rights reserved. Terms of Use | Trademarks


            You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

            AddThis Social Bookmark Button

            Leave a Reply

            *
            To prove that you're not a bot, enter this code
            Anti-Spam Image