title: Line that doesn't exist being included in dynamic code coverage analysis in Visual Studio 2017
body: <p>I am trying to test out dynamic code coverage in Visual Studio 2017 for C++ following <a href="https://stackoverflow.com/questions/30806421/is-it-possible-to-get-code-coverage-data-for-integration-tests-using-visual-stud">this post</a>. However the coverage seems to be executing a line not in the program at all. This is the simple program I am using to test coverage:</p>
  
  <p><strong>ConsoleApplication3.cpp</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  int main()
  {
      cout &lt;&lt; "Running..." &lt;&lt; endl;
  
      if (false) {
          cout &lt;&lt; "shouldn't print" &lt;&lt; endl;
      }
  
  #ifdef _WIN32
      cout &lt;&lt; "Running in WIN" &lt;&lt; endl;
  #else
      cout &lt;&lt; "Running in LIN" &lt;&lt; endl;
  #endif 
  
  }
  
  </code></pre>
  
  <p>First I build using the <code>/PROFILE</code> flag (In Solution Explorer, right click the project then <code>Properties &gt; Linker &gt; Advanced &gt; Profile &gt; set to "Yes (/PROFILE)"</code>. To run my tests, I just need to execute the <code>ConsoleApplication3.exe</code>, so followed the instructions:</p>
  
  <ol>
  <li><code>codecoverage collect /session:qwerty /output:mytest.coverage .\Debug\ConsoleApplication3.exe</code> </li>
  <li><code>codecoverage shutdown /session:qwerty</code></li>
  <li><code>codecoverage analyze /output:mytestCoverage.xml .\mytest.coverage</code></li>
  </ol>
  
  <p>NOTE: according to the post I shared above, it is not mentioned that you need to include the <code>.exe</code> as an argument. It implied you could start the collecting and then run your tests once collection had started. However, this just left me with an empty report and I found this to actually generate a real report. Next I converted the resulting <code>mytest.coverage</code> file to the <code>.xml</code> format. Opening up the <code>mytestCoverage.xml</code> I see the following:</p>
  
  <p><strong>mytestCoverage.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;results&gt;
     &lt;modules&gt;
        &lt;module lines_not_covered="1" lines_partially_covered="0" lines_covered="6" blocks_not_covered="3" blocks_covered="10" line_coverage="85.71" block_coverage="76.92" id="A62F1CFD667E27408B95EED542B0A03801000000" path="consoleapplication3.exe" name="consoleapplication3.exe"&gt;
           &lt;functions&gt;
              &lt;function lines_not_covered="1" lines_partially_covered="0" lines_covered="6" blocks_not_covered="3" blocks_covered="10" line_coverage="85.71" block_coverage="76.92" id="6832" name="_main" type_name=""&gt;
                 &lt;ranges&gt;
                    &lt;range end_column="0" end_line="6" start_column="0" start_line="6" covered="yes" source_id="0" /&gt;
                    &lt;range end_column="0" end_line="7" start_column="0" start_line="7" covered="yes" source_id="0" /&gt;
                    &lt;range end_column="0" end_line="9" start_column="0" start_line="9" covered="yes" source_id="0" /&gt;
                    &lt;range end_column="0" end_line="10" start_column="0" start_line="10" covered="no" source_id="0" /&gt;
                    &lt;range end_column="0" end_line="14" start_column="0" start_line="14" covered="yes" source_id="0" /&gt;
                    &lt;range end_column="0" end_line="19" start_column="0" start_line="19" covered="yes" source_id="0" /&gt;
                    &lt;range end_column="0" end_line="15732480" start_column="0" start_line="15732480" covered="yes" source_id="0"/&gt;
                 &lt;/ranges&gt;
              &lt;/function&gt;
           &lt;/functions&gt;
           -
           &lt;source_files&gt;
              &lt;source_file id="0" path="c:\users\sakeeb_hossain\source\repos\consoleapplication3\consoleapplication3.cpp" checksum="87CCE2DD760287BB1A6A3CCF2BF8B930" checksum_type="MD5" /&gt;
           &lt;/source_files&gt;
        &lt;/module&gt;
     &lt;/modules&gt;
  &lt;/results&gt;
  </code></pre>
  
  <p>Take a look at the last <code>&lt;range&gt;</code> tag. My question is where is that coming from and how do I get rid of it (other than manually editing of course)? </p>