{"id":65,"date":"2010-09-27T08:33:00","date_gmt":"2010-09-27T08:33:00","guid":{"rendered":"https:\/\/wdev-blog.azurewebsites.net\/index.php\/2010\/09\/27\/c-warning-cs0067-the-event-event-is-never-used\/"},"modified":"2010-09-27T08:33:00","modified_gmt":"2010-09-27T08:33:00","slug":"c-warning-cs0067-the-event-event-is-never-used","status":"publish","type":"post","link":"http:\/\/panahy.nl\/index.php\/2010\/09\/27\/c-warning-cs0067-the-event-event-is-never-used\/","title":{"rendered":"C# Warning CS0067: The event &#8216;event&#8217; is never used"},"content":{"rendered":"<div>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:    <\/p>\n<pre><br \/>    <span style=\"color: #0000FF;\">#region<\/span><span style=\"color: #000000;\"> INotifyPropertyChanged Members<\/span><br \/>    <span style=\"color: #0000FF;\">public<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #0000FF;\">event<\/span><span style=\"color: #000000;\"> System.ComponentModel.PropertyChangedEventHandler PropertyChanged;<\/span><br \/><br \/>    <span style=\"color: #0000FF;\">#endregion<\/span><span style=\"color: #000000;\"><\/span><br \/>    <span style=\"color: #0000FF;\">#region<\/span><span style=\"color: #000000;\"> INotifyPropertyChanging Members<\/span><br \/>    <span style=\"color: #0000FF;\">public<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #0000FF;\">event<\/span><span style=\"color: #000000;\"> System.ComponentModel.PropertyChangingEventHandler PropertyChanging;<\/span><br \/><br \/>    <\/pre>\n<\/div>\n<div>These two events have no meaning in my class and I just have to implement them for the sake of the interface.<\/p>\n<p>As I start to compile my code I see the <strong>Warning CS0067<\/strong> that indicates that my events are not used anywhere, which is true.<\/p>\n<p>As usual, I don&#8217;t want my code gets spoiled with warnings en I would like to sort out ALL MY WARNINGS. So I came across some options:<\/p>\n<ul><\/p>\n<li>Ignoring this warnig throughout the project.\n<p>This is too much, I don&#8217;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 <strong>Supress warnings<\/strong><\/li>\n<p><\/p>\n<li>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:\n<pre><span style=\"color: #0000FF;\">#pragma<\/span><span style=\"color: #000000;\"> warning disable 0067<\/span><\/pre>\n<p>and then restore it after my declaration using  <\/p>\n<pre><span style=\"color: #0000FF;\">#pragma<\/span><span style=\"color: #000000;\"> warning restore 0067<\/span><\/pre>\n<p><\/li>\n<li>The last option I just found from <a href=\"http:\/\/blogs.msdn.com\/b\/trevor\/archive\/2008\/08\/14\/c-warning-cs0067-the-event-event-is-never-used.aspx\" target=\"_blank\" rel=\"noopener\">MSDN<\/a> 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.\n<p>To do so I need to throw an exception as follows:    <\/p>\n<pre><span style=\"color: #0000FF;\">public<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #0000FF;\">event<\/span><span style=\"color: #000000;\"> System.ComponentModel.PropertyChangedEventHandler PropertyChanged<br \/>{<br \/>  <\/span><span style=\"color: #0000FF;\">add<\/span><span style=\"color: #000000;\"> { <\/span><span style=\"color: #0000FF;\">throw<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #0000FF;\">new<\/span><span style=\"color: #000000;\"> NotSupportedException(); }<br \/>  <\/span><span style=\"color: #0000FF;\">remove<\/span><span style=\"color: #000000;\"> { }<br \/>}<br \/><br \/><\/span><span style=\"color: #0000FF;\">public<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #0000FF;\">event<\/span><span style=\"color: #000000;\"> System.ComponentModel.PropertyChangingEventHandler PropertyChanging<br \/>{<br \/>  <\/span><span style=\"color: #0000FF;\">add<\/span><span style=\"color: #000000;\"> { <\/span><span style=\"color: #0000FF;\">throw<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #0000FF;\">new<\/span><span style=\"color: #000000;\"> NotSupportedException(); }<br \/>  <\/span><span style=\"color: #0000FF;\">remove<\/span><span style=\"color: #000000;\"> { }<br \/>}<\/span><\/pre>\n<\/li>\n<\/ul>\n<p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>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 &hellip; <a href=\"http:\/\/panahy.nl\/index.php\/2010\/09\/27\/c-warning-cs0067-the-event-event-is-never-used\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;C# Warning CS0067: The event &#8216;event&#8217; is never used&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[43],"tags":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"post-thumbnail":false},"uagb_author_info":{"display_name":"Pouya Panahy","author_link":"http:\/\/panahy.nl\/index.php\/author\/pouya\/"},"uagb_comment_info":13,"uagb_excerpt":"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&hellip;","_links":{"self":[{"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/posts\/65"}],"collection":[{"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/comments?post=65"}],"version-history":[{"count":0,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/posts\/65\/revisions"}],"wp:attachment":[{"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/media?parent=65"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/categories?post=65"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/tags?post=65"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}