'ByRef' parameter <parametername> cannot be used in a query expression

A parameter included in a LINQ query is a pointer type. Parameters used in query expressions cannot be passed by reference.

Error ID: BC36533

To correct this error

  • Declare a new variable and assign the value of the new variable to a copy of the value that is passed by reference. Use the copied variable in the LINQ query. The following is an example:

    Sub RunQuery(ByVal collection As List(Of Integer), _
                 ByRef filterValue As Integer)
        Dim fv = filterValue
        Dim queryResult = From num In collection _
                          Where num < fv
    End Sub
    

To correct this error

  • Replace the ByRef keyword with the ByVal keyword for the parameter used in the query.

See Also

Concepts

Differences Between Passing an Argument By Value and By Reference

Introduction to LINQ in Visual Basic

Other Resources

LINQ in Visual Basic