Tuesday, November 17, 2015

Visual Basic Implements Error

The other day a coworker was getting a strange error in Visual Studio:

Statement is not valid inside a method/multiline lambda.

 The code causing the problem looked this this:

Public Function GetSupplyList() As IEnumerable(Of SupplyItemDto)
                                    Implements IReadData.GetSupplyList


It took us a minute to realize that in Visual Basic.NET the Implements on a function has to be on the same line as the function. You can also use a line continuation character ("_") to fix the issue.


Of course, this is the exact opposite of  Implements on a class where the Implements keyword has to be on the next line or you'll get "End of statement expected".


No comments: