Bug in XML literals around the Imports keywords..

 In VB9, there’s a bug when using XML literals with any type member that is a protected keyword.  For example, given the following psuedo types,

 

Class Doc
   Public Property [Imports]() As List(Of DocImports)
End Class

Class DocImports
 
  Public Property [Namespace]() As String

End Class

 

The following code won’t compile:

 

Dim d As New Doc

Dim xml = <?xml version=1.0 encoding=utf-8?>
                <Imports>
                   <%= From item In d.Imports _
                      Select <Import><Namespace><%= item.Namespace %></Namespace></Import> %>
                </Imports>

 

The trick is to escape the Imports property inside the the XML query:

Dim xml = <?xml version=1.0 encoding=utf-8?>
                <Imports>
                   <%= From item In d.[Imports] _
                      Select <Import><Namespace><%= item.Namespace %></Namespace></Import> %>
                </Imports>

 

 

This seems to only apply to some keywords, not all. Imports, Sub, Function all cause the problem, yet Class, Private and Namespace don’t.  One thing you’ll see is the <%= substitution block won’t get the characteristic highlight colour.

 

And another quirk is if the property is called Option, VB will colour that as if it is a keyword even when it is a property such as stock.Option.  This one only seems to impact Option, and does not impact the actual compile, only code aesthetics 😉



2 Comments so far

  1.   Avner Aharoni on November 24th, 2007          

    Thanks for reporting this bug Bill. I have logged it in our bug system.

    Regards,
    Avner Aharoni
    Program Manager
    Microsoft

  2.   bill on November 24th, 2007          

    Thanks 🙂