XML literal cannot appear here unless it is enclosed in parentheses

An XML literal declaration is used in an expression in a location that is ambiguous to the Visual Basic compiler. That is, the Visual Basic compiler cannot determine whether the less-than character (<) is intended as a comparative operator or the start of an XML literal. The following code provides an example:

[Visual Basic]

' Generates an error.
Dim queryResult = From element In elements _
                  Where <sample>Value</sample> = "Value" _
                  Select element

Error ID: BC31198

To correct this error

  • Enclose the XML literal declaration in parentheses, as shown in the following example:

    Dim queryResult = From element In elements _
                      Where (<sample> Value</sample>) = "Value" _
                      Select element
    
  • Modify your code to refer to an existing XML literal, as shown in the following example:

    Dim queryResult = From element In elements _
                      Where e.<sample>.Value = "Value" _
                      Select element
    

See Also

Other Resources

XML Literals

XML Axis Properties

XML in Visual Basic