Search code examples
vb.netmonomonodevelopxamarin-studio

Old Visual Basic code fails on @ symbol with VBNC30037


I have very old VB code that looks like this:

Private Sub Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Save.Click
    Dim webClient As CookieAwareWebClient = New CookieAwareWebClient()
    Dim result As String
    Dim request As XElement = New XElement("request")
    request.@operation = "UpdateAds"
    For i As Integer = 0 To adsList.Count - 1
        Dim ad As Advertisement = adsList(i)
        Dim adElement As XElement = New XElement("advertisement")
        adElement.@id = ad.id
        adElement.@image_path = ad.image_path
        adElement.@name = ad.name

I'm trying to compile this with Mono using Xamarin Studio. Regular VB compiles fine, but I get a error VBNC30037: Symbol is not valid whenever the @ symbol appears.

I'm not enough of a VB developer to know what the @ here means and why this won't compile, since it did at one time compile in VB. I've tried Googling to no avail.

So, I'd like to know if there's something I'm doing wrong in Xamarin Studio or if there's some syntax change I can make to replace the @ with something that compiles.


Solution

  • This @ is shorthand for an XML Attribute value: enter image description here

    So you may be able to re-write this as follows:

    Original shorthand:

    request.@operation = "UpdateAds"
    

    Re-write longhand:

    request.Attribute("operation").Value = "UpdateAds"