C# Warning CS0067: The event ‘event’ is never used

In my current project I am using a library that is delivered to me. The API in this library provide an interface that is a bit big! The interface requires my class to implement two events as follows:


#region INotifyPropertyChanged Members
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

#endregion
#region INotifyPropertyChanging Members
public event System.ComponentModel.PropertyChangingEventHandler PropertyChanging;

These two events have no meaning in my class and I just have to implement them for the sake of the interface.

As I start to compile my code I see the Warning CS0067 that indicates that my events are not used anywhere, which is true.

As usual, I don’t want my code gets spoiled with warnings en I would like to sort out ALL MY WARNINGS. So I came across some options:

  • Ignoring this warnig throughout the project.

    This is too much, I don’t want to avoid the benefit of getting this nice warning that just highlighted my problem. But if I would like to do so I need to put the number 0067 in the project properties page in Build tab onder the Supress warnings

  • The less wide solution would be to ignore this warning only in that file and I could do this by putting the code just before my declaration:
    #pragma warning disable 0067

    and then restore it after my declaration using

    #pragma warning restore 0067

  • The last option I just found from MSDN which seems a neat solution is to tell the compiler that I am deliberately not supporting this event and even if it would be called at runtime that would be a mistake.

    To do so I need to throw an exception as follows:

    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged
    {
    add { throw new NotSupportedException(); }
    remove { }
    }

    public event System.ComponentModel.PropertyChangingEventHandler PropertyChanging
    {
    add { throw new NotSupportedException(); }
    remove { }
    }

Author: Pouya Panahy

Microsoft certified DevOps engineer with passion in analysing, designing and implementing solutions for Azure Cloud with hands-on experience in security and quality assurence.

13 thoughts on “C# Warning CS0067: The event ‘event’ is never used”

  1. You make a great point. Got some great information here. I think that if more people thought about it that way, theyd have a better time understanding the issue. Your view is definitely something Id like to see more of. Thanks for this blog. Its fantastic and so is what youve got to say.

  2. Wow, just what information I need it.
    I spent hours to find Attribute which can supress CS0067 warning message not found nothing.

    ASFAIK, the last option is best, since it obviously declares PropertyChange is not supported, and make code more readable.

  3. Hi,

    Thanks for sharing this link – but unfortunately it seems to be down? Does anybody here at wdevs.blogspot.com have a mirror or another source?

    Thanks,
    James

  4. Greetings! I know this is kinda off topic but I was wondering if you knew where I could get a captcha plugin for my comment form? I'm using the same blog platform as yours and I'm having trouble finding one? Thanks a lot!

  5. I am asking for my mother. She doesn't necessarily want to make money off them, her purpose is to use her blog (once popular) and use it as references to possibly help her get a newspaper article. She has a title for one called "Answers to Life's Problems". Where can she post blogs and they become popular? She posted it already on WordPress but there are 3 million people posting blogs hers gets lost in the mix. Any suggestions?.

    PoIuYt

Leave a Reply