Tool to detect missing disposes - c#

im searching for any tool that can detect any missing dispose calls on classes that do data access and file operations. And if it checks another performance issues it will be nice.
BTW, i need to run the tool over the code, not on the execution. Thanks!

DevExpress CodeRush does this for you:
see this article: Code Issues – Undisposed local
Code Rush home: DevExpress CodeRush
I have used the express version of this tool and personally I like it more than ReSharper.

The open-source Gendarme tool provides several rules wrt IDisposable.
disclaimer: I'm Gendarme's maintainer.

If you prefer a free utility, FxCop does this.

Related

Optimization tool in Visual Studio

I accidently saw that there is a feature in VS2010 (built in, I believe) which tells you how to make your c# code more good looking, i.e. "it's better to write here not like this, but like this", but I couldn't find this tool. And one more question, is there any tool, which can perform the code analysis for unhandled exceptions?
I highly suggest: Resharper plug-in.
Sounds like you're talking about FxCop.
Could be StyleCop, though I sometimes question it's fashion taste. StyleCop enforces consistency in code style (aka "better looking") but does nothing semantically to the code. Visual Studio's built in Code Analysis is about semantics and grew out of FxCop.

Is there anyway to trace all classes and interfaces used or referenced in a C# project?

I have a huge cryptography solution that has way more than what we need. I need some way of debugging the program and keeping track of each class that was called after running my main() method. Any tips? Right now I'm attepting to hold down F11 and go through all the classes that opened up one by one and manually check what was called. Not what I want to do. I'm stripping out everything that wasn't needed afterwards for memory leak, performance, and size reasons. It's open source code. Visual Studio 2008
Dottrace should do the trick for you. It has a really handy way of profiling any running .NET code and spitting out an easy-to-consume report. I highly recommend the tool (it's also good for what it's designed for - performance & memory profiling). This sounds like an ad, but I have nothing to do with the company. I just love the app.
You can use the .NET Reflector tool. Also this is a built-in feature in Visual Studio 2010.
Tracing has always been the default showcase for AOP.
PostSharp: http://www.sharpcrafters.com/aop.net

Is there an automatic way in ASP.NET to tell which resources are not used anywhere in code and markup?

I believe lots of us have been presented with a challenge to check manually through hundreds of string constants to check which ones are used and which are not (orphans). Although I do not have that many yet in my current project, I still find it difficult already to do a code review and check for dropped constants manually.
Is there any way to automate this? Maybe some secret hidden feature in VS?
I have an ASP.NET MVC project with VS 2008. So I'd like to check for all possible references to resources in both .cs and .aspx files.
My guess is that would not be possible. Still, maybe there is something to help me with this task?
CodeRush from Developer Express provides all sorts of orphan checks. They just released a free version - CodeRush Express - although I'm not entirely sure what features are in the free version. Would seem plausible that a feature like this would have been left in, though.
It's a pretty powerful tool, so I'd recommend it anyway.
Also Resharper is the best tool for VS IDE,it does all that for you plus many other options.
hope this helps.
NDepend supports searching for unused public methods / properties etc. Also, Resharper 4.5 now highlights all unused non-private members if you turn on solution wide analysis.

How do I find and remove unused classes to cleanup my code?

Is there a quick way to detect classes in my application that are never used? I have just taken over a project and I am trying to do some cleanup.
I do have ReSharper if that helps.
I don't recommend deleting old code on a new-to-you project. That's really asking for trouble. In the best case, it might tidy things up for you, but isn't likely to help the compiler or your customer much. In all but the best case, something will break.
That said, I realize it doesn't really answer your question. For that, I point you to this related question:
Is there a custom FxCop rule that will detect unused PUBLIC methods?
NDepend
Resharper 4.5 (4.0 merely detects unused private members)
Build your own code quality unit-tests with Mono.Cecil (some samples could be found in the Lokad.Quality the this open source project)
Review the code carefully before you do this. Check for any uses of reflection, as classes can be loaded and methods can be dynamically invoked at runtime without knowing at compile time which ones they are.
It seems that this is one of the features proposed features for the next version of Resharper. That doesn't help yet, but hopefully the EAP is just around the corner.
Be careful with this - it is possible that you may remove things that are not needed in the immediate vicinity of the code you are working on but you run the risk of deleting interface members that other applications may rely on without your knowledge.

C# Call Graph Generation Tool

I just got a heaping pile of (mostly undocumented) C# code and I'd like to visualize it's structure before I dive in and start refactoring. I've done this in the past (in other languages) with tools that generate call graphs.
Can you recommend a good tool for facilitating the discovery of structure in C#?
UPDATE
In addition to the tools mentioned here I've seen (through the tubes) people say that .NET Reflector and CLR Profiler have this functionality. Any experience with these?
NDepend is pretty good at this. Additionally Visual Studio 2008 Team System has a bunch of features that allow you to keep track of cyclomatic complexity but its much more basic than NDepend. (Run code analysis)
Concerning NDepend, it can produce some usable call graph like for example:
The call graph can be made clearer by grouping its method by parent classes, namespaces or projects:
Find more explanations about NDepend call graph here.
It's bit late, but http://sequenceviz.codeplex.com/ is an awesome tool that shows the caller graph/Sequence diagram. The diagrams are generated by reverse engineering .NET Assemblies.
As of today (June 2017), the best tool in class is Resharper's Inspect feature. It allows you to find all incoming calls, outgoing calls, value origin/destination, etc.
The best part of ReSharper, compared to other tools mentioned above: it's less buggy.
I've used doxygen to some success. It's a little confusing, but free and it works.
Visual Studio 2010.
Plus, on a method-by-method basis - Reflector (Analyzer (Ctrl+R); "Depends On" and "Used By")
SequenceViz and DependencyStructureMatrix for Reflector might help you out: http://www.codeplex.com/reflectoraddins
I'm not sure if it will do it over just source code, but ANTS Profiler will produce a call graph for a running application (may be more useful anyway).

Categories