ReSharper Solution-wide Analysis caution

04/26/09

Permalink 12:11:37 pm, by truewill Email , 226 words, 430 views   English (US)
Categories: Tips, IoC, .NET, Tools, ReSharper

ReSharper Solution-wide Analysis caution

ReSharper version 4.5 added significant functionality to the Solution-wide Analysis feature. I have found this to be a valuable tool. However, it’s wise to be extremely cautious about removing public members that ReSharper says are never used.

I would not expect ReSharper to know about projects that are not part of the current solution. If you’re creating a shared library, you’re likely to see a lot of “unused” public members.

What was less obvious to me is that data binding is not detected by ReSharper in this context. For example, say I have a public string property named FullName on a class. ReSharper displays a hint that “Property ‘FullName’ is never used". ReSharper’s Find Usages likewise finds no references. The property may still be data-bound to a control, though, since data binding generally references the property name as a string. Removing the property would cause a runtime failure.

ReSharper’s Find Usages Advanced can be used to find the binding, if Textual occurences is checked.

“Class ‘Foo’ is never instantiated” hints may also be incorrect. IoC containers (such as Unity) or other Reflection-based techniques can fool ReSharper.

Please note that I’m not suggesting turning off Solution-wide Analysis (and if you’re not using ReSharper, you’re working harder, not smarter!). Just be aware of its limitations.

Update - August 17, 2009

The UsedImplicitlyAttribute can be used where necessary to mitigate this problem.

Comments, Pingbacks:

Comment from: Oli [Visitor] Email
Great advice! I totally agree with everything you said!
We need to be very careful what we change doesn't break anything outside the current solution!
Thanks for the tips!
PermalinkPermalink 08/13/09 @ 16:51
Comment from: SealedSun [Visitor] Email · http://www.sealedsun.ch
JetBrains.Annotations.dll (or the code that you can copy from the "Code Annotations" page in the options) defines the UsedImplicitly attribute. That in turn can be used to prevent the false positives you mentioned.

Unfortunately, you have to annotate each class AND all its members (i.e. not like DebuggerStepThrough which affects all members of a class)
PermalinkPermalink 09/11/09 @ 15:16
Comment from: Plastic Recycling [Visitor] Email · http://1800recycling.com/find/recycling-locations/plastic/
Have you tried v5.0? It seems to less buggy than previous versions. If not, you should definitely upgrade.
PermalinkPermalink 12/20/09 @ 15:35
Comment from: Property Management Software [Visitor] Email · http://www.mypropertymanagementsoftware.com
A very nice advice to anyone, ReSharper Solution is something that everyone need to know.
PermalinkPermalink 12/26/09 @ 15:28
Comment from: Anderson C. [Visitor] Email · http://coloradospringsteam.com
Yeah, I totally agree. Great Advice there. ReSharper is really one of the most intelligent add-in to Visual Studio 2008 and it has a unique code analysis for error checking.
PermalinkPermalink 12/30/09 @ 18:26

Leave a comment:

Your email address will not be displayed on this site.
Your URL will be displayed.

Allowed XHTML tags: <p, ul, ol, li, dl, dt, dd, address, blockquote, ins, del, span, bdo, br, em, strong, dfn, code, samp, kdb, var, cite, abbr, acronym, q, sub, sup, tt, i, b, big, small>
(Line breaks become <br />)
(Set cookies for name, email and url)
(Allow users to contact you through a message form (your email will NOT be displayed.))
The name truewill is composed of two other words. What is the SECOND word?

Development Central

Development Central is the blog of Bill Sorensen, a professional software developer. Much of this will relate to C#, .NET, and OOP in general.

Disclaimer
These postings are provided "AS IS" with no warranties and confer no rights.

Search

Categories

Linkblog

b2evolution

contributors

XML Feeds

What is RSS?

Who's Online?

  • Guest Users: 5

powered by b2evolution free blog software