<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Why are unused using directives not a warning?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2010/01/25/why-are-unused-using-directives-not-a-warning.aspx</link><description>As I’ve discussed before, we try to reserve warnings for only those situations where we can say with almost certainty that the code is broken, misleading or useless. One reason for trying to ensure that warnings are not “false positives” is that we don</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Why are unused using directives not a warning?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2010/01/25/why-are-unused-using-directives-not-a-warning.aspx#10020960</link><pubDate>Mon, 07 Jun 2010 15:04:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10020960</guid><dc:creator>Ray</dc:creator><description>&lt;p&gt;Not always unused usings are really unused. Parts of codes that are not being compiled due to macro directives #IF may need those &amp;quot;unused&amp;quot; usings when they actually being compiled.&lt;/p&gt;
&lt;p&gt;Resharper can clean the unused usings (and other unused code parts) automatically throughout solution for you, btw.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10020960" width="1" height="1"&gt;</description></item><item><title>re: Why are unused using directives not a warning?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2010/01/25/why-are-unused-using-directives-not-a-warning.aspx#9954963</link><pubDate>Thu, 28 Jan 2010 21:46:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9954963</guid><dc:creator>SonOfPirate</dc:creator><description>&lt;p&gt;Seems the most obvious (and easiest?) solution is to enabled severity levels for code analysis rules (this would definitely be one) and make &amp;quot;Unused Using Statements&amp;quot; report as Information. &amp;nbsp;The Error List already supports these levels, so why not use them.&lt;/p&gt;
&lt;p&gt;As an extension of this would allow filtering which rules are reported as errors and which remain warnings when &amp;quot;warnings as errors&amp;quot; is set.&lt;/p&gt;
&lt;p&gt;Just my two cents.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9954963" width="1" height="1"&gt;</description></item><item><title>re: Why are unused using directives not a warning?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2010/01/25/why-are-unused-using-directives-not-a-warning.aspx#9954872</link><pubDate>Thu, 28 Jan 2010 19:33:57 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9954872</guid><dc:creator>Jon Skeet</dc:creator><description>&lt;p&gt;@Andy: You'll get exactly the same thing if you remove all uses of a local variable, but not the declaration. In the case of using directives it's extremely easy to get rid of that warning though - or you could just ignore it, if the commenting out really is temporary.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9954872" width="1" height="1"&gt;</description></item><item><title>re: Why are unused using directives not a warning?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2010/01/25/why-are-unused-using-directives-not-a-warning.aspx#9954831</link><pubDate>Thu, 28 Jan 2010 18:16:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9954831</guid><dc:creator>Andy Turner</dc:creator><description>&lt;p&gt;It'd be annoying if I temporarily commented out some code and then started getting warnings about the now-unused Using statements.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9954831" width="1" height="1"&gt;</description></item><item><title>re: Why are unused using directives not a warning?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2010/01/25/why-are-unused-using-directives-not-a-warning.aspx#9954736</link><pubDate>Thu, 28 Jan 2010 15:59:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9954736</guid><dc:creator>David Nelson</dc:creator><description>&lt;p&gt;@Tom,&lt;/p&gt;
&lt;p&gt;&amp;quot;Bear in mind that VS only creates usings for existing references. &amp;nbsp;If you removed unwanted references when you first create your project, you won't get all those extraneous directives in every code module you add.&amp;quot;&lt;/p&gt;
&lt;p&gt;This is a complete fabrication. If I remove the extraneous System.Data and System.Xml references when I initially create a project, then not only will the extraneous using statements still be there when I add another class, but Visual Studio will actually *add* the references that I already removed! Which is why I edited the default templates to get rid of that nonsense.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9954736" width="1" height="1"&gt;</description></item><item><title>re: Why are unused using directives not a warning?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2010/01/25/why-are-unused-using-directives-not-a-warning.aspx#9954720</link><pubDate>Thu, 28 Jan 2010 15:33:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9954720</guid><dc:creator>Stuart Ballard</dc:creator><description>&lt;p&gt;@Tom: &amp;quot;Even Visual Studio 2008 Standard *without* SP1 has the option to right-click, Organize Usings, Remove Unused Usings. &amp;nbsp;How any self-respecting coder could miss this is beyond me.&amp;quot; - which is why I specifically said &amp;quot;throughout a project&amp;quot; (although what I really meant was throughout a solution). With a large codebase the idea of opening up hundreds of .cs files and right clicking each one is ridiculous. It's nice to have it in the code editor but it'd be much nicer to have it globally.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9954720" width="1" height="1"&gt;</description></item><item><title>re: Why are unused using directives not a warning?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2010/01/25/why-are-unused-using-directives-not-a-warning.aspx#9954665</link><pubDate>Thu, 28 Jan 2010 14:11:54 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9954665</guid><dc:creator>Tom</dc:creator><description>&lt;p&gt;To amend myself, I don't know if VS2005 or VS2003 have the Organize Usings option out of the box, as it's been quite a while since I've used either of them. &amp;nbsp;I apologize to the folks still using the older IDE's. &amp;nbsp;As mentioned before, you have Power Commands and other tools at your disposal. &amp;nbsp;If you don't like adding extra tools, upgrade to VS2008. &amp;nbsp;If you're not using VS at all . . . good luck to you.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9954665" width="1" height="1"&gt;</description></item><item><title>re: Why are unused using directives not a warning?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2010/01/25/why-are-unused-using-directives-not-a-warning.aspx#9954659</link><pubDate>Thu, 28 Jan 2010 14:07:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9954659</guid><dc:creator>Tom</dc:creator><description>&lt;p&gt;Naming Conventions:&lt;/p&gt;
&lt;p&gt;If your first form is called MainForm, is your second form called MainForm1? &amp;nbsp;You have the same issue, namely that the IDE developers are probably NOT psychic. &amp;nbsp;(Correct me if I'm wrong.) &amp;nbsp;They wouldn't follow this age-old convention if it didn't satsify the general market.&lt;/p&gt;
&lt;p&gt;The numeric suffix conveition has been around since before most fresh-out-of-school coders were born and is used in the vast majority of software tools name their objects using the &amp;quot;type + index&amp;quot; convention, including 3-D software. &amp;nbsp;I'd assemble a list upon request, but Eric probably doesn't want me filling up his allocated blog space.&lt;/p&gt;
&lt;p&gt;Personally, I will end up renaming my controls no matter what Microsoft calls them, just as I do with Photoshop layers, 3ds max edit objects, etc. etc.. &amp;nbsp;The idea is, protoype fast, beautify when it matters.&lt;/p&gt;
&lt;p&gt;Directive Warnings:&lt;/p&gt;
&lt;p&gt;I second the suggestion to use the Message box. &amp;nbsp;It's practically useless right now anyway.&lt;/p&gt;
&lt;p&gt;If you think unused usings are bad, try collapsing the block and see how quickly you forget about them.&lt;/p&gt;
&lt;p&gt;Even Visual Studio 2008 Standard *without* SP1 has the option to right-click, Organize Usings, Remove Unused Usings. &amp;nbsp;How any self-respecting coder could miss this is beyond me. &amp;nbsp;Methinks you should explore and understand the tools you use on a day-to-day basis to feed your family before you complain about a feature that already exists.&lt;/p&gt;
&lt;p&gt;Bear in mind that VS only creates usings for existing references. &amp;nbsp;If you removed unwanted references when you first create your project, you won't get all those extraneous directives in every code module you add. &amp;nbsp;The problem is when you remove a reference mid-development, and all those extra usings you were never warned about suddenly become errors. &amp;nbsp;That's where right-click | Organize Usings is very handy.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9954659" width="1" height="1"&gt;</description></item><item><title>re: Why are unused using directives not a warning?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2010/01/25/why-are-unused-using-directives-not-a-warning.aspx#9954288</link><pubDate>Wed, 27 Jan 2010 20:37:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9954288</guid><dc:creator>Jon Skeet</dc:creator><description>&lt;p&gt;It may be worth pointing out that an unused using directive *may* mean a bug in your code. It may be that you're using an extension method from namespace A instead of the one you intended to use from namespace B. Admittedly this is partly due to one of my very few peeves about how C# has evolved (the way that extension methods are discovered) but it really could change behaviour.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9954288" width="1" height="1"&gt;</description></item><item><title>re: Why are unused using directives not a warning?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2010/01/25/why-are-unused-using-directives-not-a-warning.aspx#9954283</link><pubDate>Wed, 27 Jan 2010 20:26:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9954283</guid><dc:creator>David Nelson</dc:creator><description>&lt;p&gt;@TaylorMichaelL,&lt;/p&gt;
&lt;p&gt;Xml comments are parsed by the compiler. If a namespace is used in the xml comments, it is not unused, and should not generate the warning.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9954283" width="1" height="1"&gt;</description></item></channel></rss>