title: MSTest C++ unit test dll not working
body: <p><strong>C# Unit Test - Runs ok</strong></p>
  
  <p>I have read the MSTest unit test (utterly useless )documentation on the microsoft website here: <a href="https://msdn.microsoft.com/en-gb/library/ms182487.aspx" rel="nofollow noreferrer">utterly-useless-ms-doc-link</a>. Then I read a whole load of other more useful links (e.g. on SO) and finally I am able to run <strong>C#</strong> unit tests no problems, like this:</p>
  
  <pre><code>mstest /testcontainer:UnitTest.dll /detail:errormessage
  </code></pre>
  
  <p><strong>C++ Unit Test - Fails</strong></p>
  
  <p>As far as I can tell this should be the same for the C++ unit tests, so I ran a similar command (specific command details at the end) for C++, but then I get the error:</p>
  
  <blockquote>
    <p>UnitTest_TrackManager.dll Unable to load the test container
    'UnitTest_TrackManager.dll' or one of its dependencies. If you build
    your test project assembly as a 64 bit assembly, it cannot be loaded.
    When you build your test project assembly, select "Any CPU" for the
    platform. To run your tests in 64 bit mode on a 64 bit processor, you
    must change your test settings in the Hosts tab to run your tests in a
    32 bit process. Error details: Could not load file or assembly
    'file:///D:\MiddlewareTest01\x64\Debug\UnitTest_TrackManager.dll'
    or one of its dependencies. The module was expected to contain an
    assembly manifest.</p>
  </blockquote>
  
  <p><strong>32-bit or 64-bit DLL?</strong></p>
  
  <p>So, fair enough, I have built the code for 64 bit and MStest is 32bit only. I used <code>dumpbin /HEADERS fname.dll</code> to check that this is a 64-bit file and it is:</p>
  
  <pre><code>File Type: DLL
  
  FILE HEADER VALUES
              8664 machine (x64)
                 D number of sections
          5829E628 time date stamp Mon Nov 14 16:28:24 2016
                 0 file pointer to symbol table
                 0 number of symbols
                F0 size of optional header
              2022 characteristics
                     Executable
                     Application can handle large (&gt;2GB) addresses
                     DLL
  </code></pre>
  
  <p>So, then I recompie for 32-bit and run the test again, but I get the same error. So I check that the file output (the DLL) is 32-bit and it does appear to be, here is the dumpbin for that:</p>
  
  <pre><code>File Type: DLL
  
  FILE HEADER VALUES
               14C machine (x86)
                 C number of sections
          5829E792 time date stamp Mon Nov 14 16:34:26 2016
                 0 file pointer to symbol table
                 0 number of symbols
                E0 size of optional header
              2102 characteristics
                     Executable
                     32 bit word machine
                     DLL
  </code></pre>
  
  <p><strong>C++ Unit Test Works in the IDE</strong></p>
  
  <p>Using MSVS2015 IDE, I can compile and run my code/unit tests and they all work (when I use the x86 build) - and they all pass. If I select x64 build then it complains.</p>
  
  <p><strong>Specific Command That Fails</strong></p>
  
  <p>Here is the exact command line I am useing:</p>
  
  <p><code>mstest /testcontainer:UnitTest_TrackManager.dll /detail:errormessage</code></p>
  
  <p>It is run from the same location as the dll lives which is here:</p>
  
  <p><code>D:\&lt;somepath&gt;\MiddlewareTest01\Debug\UnitTest_TrackManager.dll</code></p>
  
  <p>Where <code>&lt;somepath&gt;</code> is just there to hide my PC/user details and <code>MiddlewareTest01</code> is the solution folder.</p>
  
  <p>As I say, I can get this to work for C# projects, but for C++ it does not seem to work in the same way.</p>
  
  <p><strong>Update</strong></p>
  
  <p>Using dependency-walker it tells me:</p>
  
  <p><code>MICROSOFT.VISUALSTUDIO.TESTTOOLS.CPPUNITTESTFRAMEWORK.DLL</code> was not found. Could this be an issue?</p>