ray
ray

Reputation: 8699

VB.NET won't compile because of underscore

I've been running the same project on the same computer for months now in VS2010.

There have been no code changes to the class that contains the following code:

Private Event ValueChanged(ByVal sender As Object, ByVal e As EventArgs) _
    Implements STI.Shared.UI.IEditField.ValueChanged

Recently, when I compile, I get an error that my class must implement event ValueChanged.enter image description here

When I remove the underscore and bring the Implements piece to the same line, it compiles.

If I then undo checkout and revert it back to what the code was before, it compiles.

It's just very strange behavior and I'm wondering if anyone out there has experienced something like this.

Upvotes: 0

Views: 443

Answers (2)

Pondidum
Pondidum

Reputation: 11617

I can reproduce the error, but only with a slight technicallity:

Public Interface ITest

    'Note here i have specified System.EventArgs
    Event ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs)  

End Interface

Public Class TestFail
    Implements ITest

    'And here I have only specified EventArgs, which is fine...
    Private Event ValueChanged(ByVal sender As Object, ByVal e As EventArgs) Implements ITest.ValueChanged

End Class

'Unless you declare another class called EventArgs in the same namespace...
Public Class EventArgs

End Class


Public Class TestWin
    Implements ITest

    'It should work if you just prefix the EventArgs with System though, like so:
    Private Event ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Implements ITest.ValueChanged

End Class

And this is the errors you will get from it:

Error List

Upvotes: 1

DarinH
DarinH

Reputation: 4879

You don't need the underscore in that situation. Having the underscore in this case isn't even valid syntax. That does seem a bit strange. Seems like Implements would be considered an argument to the CLASS statement, but it's not. It's considered a context sensitive statement all it's own.

Upvotes: 0

Related Questions