If the file exists, it is usually a prerequisite, you should use Contract.Requires (). Enabling contract validation is optional and is usually not included in the Release assembly. Because of what your test disappears.
Honestly, you should not write such code. Any attempt to use the file throws an exception, it will be more informative than your version. It contains the name of a file that cannot be found. Moreover, File.Exists () is unreliable in a multitasking operating system. A thread can be pre-skipped right after calling Exists (), and another thread in another process can delete the file. And you will have a heisenbug on hand: you will get a FileNotFound exception, even if you tested its existence.
My call: just delete the statement. This causes more problems than it solves.
source share