While attempting to improve my code coverage in Visual Studio 2014, I suddenly found myself getting the error “Value does not fall within the expected range” when running unit tests with code coverage enabled. Without code coverage, the tests ran fine. With code coverage, that error would appear twice in the test output.
I googled the error for awhile and mostly came up empty. I eventually tracked down this post where a user was getting the same message but related to website profiling. It did help me track down the issue though.
The solution
I looked in the configuration manager. It turns out that while most of the projects in my solution were set to the “Any CPU” platform, I had one Wix installer project set to “x86”, presumably because it’s building an x86-compatible installer. If this project is disabled, code coverage works. If re-enabled, I get the error. For now, I’ve just been disabling the program when I want to do code coverage.