Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event Monitor Doesn't Detect Events on Interface #821

ArdentLogician opened this issue Apr 1, 2018 · 2 comments

Event Monitor Doesn't Detect Events on Interface #821

ArdentLogician opened this issue Apr 1, 2018 · 2 comments


Copy link

@ArdentLogician ArdentLogician commented Apr 1, 2018


public Interface ITest : INotifyPropertyChanged {...}
public class Test : ITest {...}

I would expect:

var subject = new Test() as ITest;
using(var monitor = subject.Monitor()) {....}

would be a reasonable test. Currently, the Monitor() extension method throws an exception saying the object has no events. From looking at the code, it would appear this is because it depends on the Type.GetEvents() method, which does not consider interface inheritance in its examination. As far as I'm concerned, that would easily be argued as a bug in the .NET Framework, but given how long it's been there and the potentially breaking nature of a change, I don't imagine we will see it changed ever.

Replacing this code is likely non-trivial, but not overly hard either (and if I have time I will try to get around to it if nobody beats me to the punch), given that interfaces show up differently in the type hierarchy than base classes do.

Ignoring the contrived nature of cast to ITest in the above sample, the problem is showing up for me when trying to write tests to the interface (ie. the contract) when I don't know the object implementing it because I have the same tests for multiple objects implementing the interface (Liskov substitution).

@dennisdoomen dennisdoomen self-assigned this Sep 9, 2018
@dennisdoomen dennisdoomen removed their assignment Nov 19, 2018
Copy link

@ManuKle ManuKle commented Mar 6, 2019

I just ran into the same problem.

new event PropertyChangedEventHandler PropertyChanged;
to the interface ITest is a workaround, but not having to add this manually would obviously be an improvement.

Copy link

@dennisdoomen dennisdoomen commented Jun 1, 2019

Fixed by #1012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants