Why does the VB.NET compiler think that an interface is not implemented when it is?

Update

I do not think that I was clear enough when I originally posted this question.

Take a look at these screenshots.

alt text ( Link to a large screenshot here )

Pay attention to the parts that I put in red. The class shown here executes INotifyPropertyChanged , but the VB compiler seems to believe that the PropertyChanged event declared does not match the INotifyPropertyChanged.PropertyChanged signature.

alt text ( Link to a large screenshot here )

Here I selected a line of code violation. Between this and the next screenshot, I literally just cut and pasted the same line back into the file (i.e. I pressed Ctrl + X and then Ctrl + V ).

alt text ( Link to a large screenshot here )

Now here! After cutting and pasting the line back, the error disappears.

What's going on here?


Original question

This happens to me sometimes, especially with the INotifyPropertyChanged interface in my experience, but I have no idea if the problem is limited to this single interface (which would seem strange) or not.

Say I have code like this. There is an interface with a single event. The class implements this interface. It includes an event.

 Public Interface INotifyPropertyChanged Event PropertyChanged As PropertyChangedEventHandler End Interface Public Class Person Implements INotifyPropertyChanged Public Event PropertyChanged _ (ByVal sender As Object, ByVal e As PropertyChangedEventArgs) _ Implements INotifyPropertyChanged.PropertyChanged ' more code below ' End Class 

From time to time, when I build my project, the compiler will suddenly begin to act, like the previous code. It will report that the Person class does not implement INotifyPropertyChanged because it does not have a PropertyChanged event; or he will say that the PropertyChanged event cannot implement INotifyPropertyChanged.PropertyChanged because their signatures do not match.

This is pretty weird, but the weirdest part is here: if I just cut the line starting with Event PropertyChanged and then paste it back in, the error disappears. The project is building.

Does anyone know what can be done here?

+4
source share
2 answers

The code works fine for me (Visual Studio 2008), you should run into some error.

Anyway, you can also implement it as follows:

 Public Class Person Implements INotifyPropertyChanged Public Event PropertyChanged As PropertyChangedEventHandler _ Implements INotifyPropertyChanged.PropertyChanged End Class 
+2
source

You need to mark the event Public

+1
source

Source: https://habr.com/ru/post/1306490/


All Articles