Reputation: 845
I have this interface
Interface IProDataSource
Delegate Sub DstartingHandler(ByVal sender As Object, ByVal e As EventArgs)
Event starting_Sinc As DstartingHandler
End Interface
Trying to use the interface like this
Public Class DataSource : Implements IProDataSource
Public Event starting_Sinc As DstartingHandler Implements IProDataSource.starting_Sinc
Public Delegate Sub DstartingHandler(ByVal sender As Object, ByVal e As EventArgs)
End Class
Gives me the next error
Event 'starting_Sinc' cannot implement event 'starting_Sinc' on interface 'IProDataSource' because their delegate types 'DstartingHandler' and 'IProDataSource.DstartingHandler' do not match.
Upvotes: 1
Views: 1261
Reputation: 941635
You'll need to move the delegate declaration outside of the interface and declare it public. All types used by an interface must be public when the class that implements them is public. Necessarily so or the client code could never assign the event. Thus:
Public Delegate Sub DstartingHandler(ByVal sender As Object, ByVal e As EventArgs)
Interface IProDataSource
Event starting_Sinc As DstartingHandler
End Interface
Public Class DataSource : Implements IProDataSource
Public Event starting_Sinc(ByVal sender As Object, ByVal e As System.EventArgs) Implements IProDataSource.starting_Sinc
End Class
If you limit the accessibility of the class you can use your original approach:
Interface IProDataSource
Delegate Sub DstartingHandler(ByVal sender As Object, ByVal e As EventArgs)
Event starting_Sinc As DstartingHandler
End Interface
Friend Class DataSource : Implements IProDataSource
Public Event starting_Sinc(ByVal sender As Object, ByVal e As System.EventArgs) Implements IProDataSource.starting_Sinc
End Class
Upvotes: 1
Reputation: 754853
The reason why is you now have 2 instances of the delegate DstartingHandler
defined in your application. One inside of DataSource
and the other inside of IProDataSource
. The one in DataSource
appears to be an error and deleting it should fix all of your problems.
EDIT
I tried the following code and it compiles
Class C1
Implements IProDataSource
Public Event starting_Sinc(ByVal sender As Object, ByVal e As System.EventArgs) Implements IProDataSource.starting_Sinc
End Class
Upvotes: 1