This is what you are looking for:
System.Diagnostics.Debug.Assert(!double.IsNan(x), "Some message shown if assert fails".)
It is ignored when compiling in Release mode, so there is no impact on performance (unless you're in Debug mode of course).