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 { }
    }

Windows Communication Foundation Built-In Bindings

Windows Communication Foundation Built-In Bindings

Binding Class Name Transport Message Encoding Message Version Security Mode Reliable Messaging Transaction Flow (disabled by default)
BasicHttpBinding HTTP Text SOAP 1.1 None Not Supported Not Supported
WSHttpBinding HTTP Text SOAP 1.2 WS-Addressing 1.0 Message Disabled WS-AtomicTransactions
WSDualHttpBinding HTTP Text SOAP 1.2 WS-Addressing 1.0 Message Enabled WS-AtomicTransactions
WSFederationHttpBinding HTTP Text SOAP 1.2 WS-Addressing 1.0 Message Disabled WS-AtomicTransactions
NetTcpBinding TCP Binary SOAP 1.2 Transport Disabled OleTransactions
NetPeerTcpBinding P2P Binary SOAP 1.2 Transport Not Supported Not Supported
NetNamedPipesBinding Named Pipes Binary SOAP 1.2 Transport Not Supported OleTransactions
NetMsmqBinding MSMQ Binary SOAP 1.2 Message Not Supported Not Supported
MsmqIntegrationBinding MSMQ Not Supported (uses a pre-WCF serialization format) Not Supported Transport Not Supported Not Supported
CustomBinding You Decide You Decide You Decide You Decide You Decide You Decide