WillFuqua

Finding Dead C# Code in an ASP.NET application

Large, long-lasting codebases tend to accumulate unused code, or dead code, over time. This happens as features are added, changed and removed.

Some types of dead code, like unreferenced methods, are easy to detect with Visual Studio’s out-of-the-box static analysis. However, other types of dead code are trickier; maybe there’s a method that’s only referenced by unit tests, or it’s referenced under a condition that’s never valid:

if (DateTime.Now < new DateTime(1970, 1, 1))
{
    // some dead code
}

How can we detect this type of dead code? Rather than using static analysis to detect it, we can use dynamic analysis—the same technique continue.

tagged as , and