Do implement methods that throw NotImplementedException

Rule ND1312 Design

Warns about methods using NotImplementedException: a temporary facility to declare a method stub deferring implementation (useful in TDD where tests fail until implemented). Before releasing, it shouldn't be used anywhere.

Don't use it permanently to mean this method should be overriden or this facility is unsupported — use abstract methods/classes instead, favoring compile time errors over run-time errors.

How to fix

Investigate why NotImplementedException is still thrown.

Severity is High if the method only throws it: the method should be implemented, is bad run-time-error-by-design, or is a removable stub. Severity is Medium if thrown from a method with significant logic: often the fix is throwing another type like InvalidOperationException.

CQLinq source

This rule is written in CQLinq, C# LINQ over the NDepend code model. It ships with every new NDepend project: you can read it, adapt it, or use it as a starting point for your own custom rules.

// <Name>Do implement methods that throw NotImplementedException</Name>
// <Id>ND1312:DoImplementMethodsThatThrowNotImplementedException</Id>

warnif count > 0
from m in JustMyCode.Methods
where m.CreateA("System.NotImplementedException".AllowNoMatch())
select new {
   m,
   m.NbLinesOfCode,
   Debt = (m.NbLinesOfCode == 1 ? 10 : 3).ToMinutes().ToDebt(),
   Severity = m.NbLinesOfCode == 1 ? Severity.High : Severity.Medium
}

//<Expl>
// The *{0}* throws *NotImplementedException*.  
// Implement the missing functionality or refactor to remove 
// this method or the usage of this exception class.
//</Expl>

//<Desc>
// Warns about methods using *NotImplementedException*: a *temporary*
// facility to declare a method *stub* deferring implementation (useful in
// **TDD** where tests fail until implemented). Before releasing, it
// shouldn't be used anywhere.
//
// Don't use it permanently to mean *this method should be overriden* or
// *this facility is unsupported* — use *abstract* methods/classes instead,
// favoring *compile time* errors over *run-time* errors.
//</Desc>

//<HowToFix>
// Investigate why *NotImplementedException* is still thrown.
//
// Severity is **High** if the method only throws it: the method should be
// implemented, is bad *run-time*-error-by-design, or is a removable stub.
// Severity is **Medium** if thrown from a method with significant logic:
// often the fix is throwing another type like **InvalidOperationException**.
//</HowToFix>

Design: all 16 items