1

During a refactor of some code, I've started getting this error. As far as I can tell I haven't changed anything that would affect this, nor have I changed the method signature.

Here is the method:

Public Sub DisplayMessage(msg as String, callBack As System.EventHandler) Implements IMyInterface.DisplayMessage

    ...

End Sub

And here's how it's called:

MessageInstance.DisplayMessage("test", _
    AddressOf MyFunc)

And MyFunc is just:

Private Sub MyFunc()
   ...
End Sub

I currently have two versions of the code, the refactored one is giving the compile error:

Argument matching parameter 'callBack' narrows to 'System.EventHandler'

And the previous version is not.

The only change that has been made to this is that the the DisplayMessage function, and the MessageInstance class has move into a separate library. Can anyone provide an explanation as to why this error is occurring or, preferably, why it is NOW occurring?

Paul Michaels
  • 16,185
  • 43
  • 146
  • 269
  • You didn't turn Option Strict On did you? – Jon Egerton Jan 03 '14 at 12:54
  • No, I just checked, and it's default (which I believe is off) everywhere. I tried explicitly setting it to Off (even though as a C# dev that makes me feel dirty), but to no avail. – Paul Michaels Jan 03 '14 at 12:58
  • It shouldn't compile, MyFunc's signature doesn't match the delegate. Just fix the code, `Sub MyFunc(ByVal sender As Object, ByVal e As EventArgs)`. – Hans Passant Jan 03 '14 at 15:07

0 Answers0