Running code coverage analysis on VS 2012 throwing

2020-04-20 18:41发布

I suddenly started getting following exception while I am trying to run the code coverage in VS 2012:

Exception was thrown: Code Coverage Analysis engine threw exception(s): Coverage file "........coverage" is invalid or corrupt

Any solution/ workaround would be helpful.

2条回答
▲ chillily
2楼-- · 2020-04-20 19:30

I have seen this error in VS2010 and it's frustrating to say the least. The error is likely related to one or more assemblies that don't get "instrumented" correctly, From memory I recall it can be solved by unselecting "instrument assemblies in place" in the test settings.

Regarding "instrumenting in place", when code coverage is turned on Visual Studio takes a few moments before the TestRun to rewrite the IL for your assemblies so that it can record which parts of the IL are executed. "Instrumenting in place" creates a back up of the assembly with a ".instr" extension, runs the tests with the profiler turned on, then replaces the instrumented assembly with the original assembly after the Tests complete. When i was seeing this error it seemed as though the original file could not be restored (possibly locked) and i had a few remnant ".instr" assemblies in my build output folder. My theory is that the IDE tries to correlate the coverage data to the original assembly but fails because of this mismatch.

AFAIK, there are no visible differences to turning off in place instrumentation when viewing coverage locally.

查看更多
Bombasti
3楼-- · 2020-04-20 19:47

I had this error on VS 2012 Premium. I fixed it by applying VS Update 1 and haven't seen it since.

查看更多
登录 后发表回答