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 ;)

This entry was posted in 2087, 2088, 491, 5162, 6183, 6184. Bookmark the permalink.

2 Responses to Bug in XML literals around the Imports keywords..

  1. Avner Aharoni says:

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

    Regards,
    Avner Aharoni
    Program Manager
    Microsoft

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>