我在尝试在VB.NET中添加事件处理程序时得到ArgumentException
。
Delegate to an instance method cannot have null 'this'
此处发生异常:
AddHandler MyClass.SomePropertyChanged, AddressOf MySecondClass.HandleSomePropertyChanged
类:
Class MyClass
Public Event SomePropertyChanged(ByVal sender As Object, ByVal e As SomePropertyChangedEventArgs)
Protected Overridable Sub OnSomePropertyChanged(ByVal e As SomePropertyChangedEventArgs)
RaiseEvent SomePropertyChanged(Me, e)
End Sub
'I'm raising the event like this:
OnSomePropertyChanged(New SomePropertyChangedEventArgs("Rating", 0.09))
End Class
Class MySecondClass
Public Sub HandleSomePropertyChanged(ByVal sender As Object, ByVal e As SomePropertyChangedEventArgs)
'...
End Sub
End Class
EventArgs我定义为:
Public Class SomePropertyChangedEventArgs
Inherits EventArgs
Public Property PropertyName As String
Public Property Value As Object
End Class
我不知道这里有什么问题 -
答案 0 :(得分:1)
这似乎表明在这一行:
AddHandler MyClass.SomePropertyChanged, AddressOf MySecondClass.HandleSomePropertyChanged
您的MySecondClass
变量为Nothing
。