title: All tests fail, Unable to get type, and FileNotFoundException if certain line of code in one test after adding fmod Visual C++ test
body: <p>I've figured out what caused the problem but I still don't know why - it happened when I started using <code>fmod</code>, and it must have something to do with how the linker decides to bring in and execute static libraries and <code>.dll</code>'s.  My code under test is a static lib;  it refers to <code>fmodex_vc</code>, another static lib, which at some point (though I know not when) decides to load in its <code>fmodex.dll</code>.  (Which is in the same directory as everything else, so I don't know why it wouldn't find it.)  As far as I know, the code under test absolutely does not call the fmod initialization functions, but maybe fmod has some static global initializers that initialize themselves and load in the dll?  And that code only gets pulled in if code in a module that uses it gets...used?</p>
  
  <p>I'm testing unmanaged C++ code using the Visual Studio test framework and when I started using fmod it stopped working: Every test, even "test" tests that do nothing, would report (wrapped for readability):</p>
  
  <pre><code>Unable to get type SlidersTest.UnitTest1, SlidersTest.
      Error: System.IO.FileNotFoundException: 
      The specified module could not be found.
      (Exception from HRESULT: 0x8007007E)
  </code></pre>
  
  <p>After a lot of trial and error, excluding <code>.cpp</code> files and re-adding them, I discovered that only one of the test files elicits the problem; and it only does if this line is called:</p>
  
  <pre><code>EntityMgr::Init();
  </code></pre>
  
  <p>Interestingly, <em>all</em> the tests start failing with that message if that line is in the code.  <code>EntityMgr::Init()</code> is a function that does very little:</p>
  
  <pre><code>EntityMgr* EntityMgr::instG = null;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>void EntityMgr::Init()
  {
     instG = new EntityMgr;
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>class EntityMgr
  {
  private:
     static EntityMgr* instG;
  public:
     EntityMgr()   // does nothing beyond the default 
     {
     }
  
     static void Init();
     static EntityMgr* Inst() { return instG; }
  
     ...
  
     vector&lt;Entity&gt; entitiesG;
  };
  </code></pre>
  
  <p><code>Entity</code>, FWIW, is a pretty vanilla class with no pointers, just various <code>float</code>s for its fields.</p>
  
  <ul>
  <li>No matter how I run the tests (from test view, run selected, run all, run from the command line, from the test menu) I get the error.</li>
  <li>Attempting to step into the test with the debugger fails - the test fails before the debugger gets to step in.  Setting the debugger to break on System exceptions did nothing as well.</li>
  <li>The code under test is a static .lib.  CLR support is <code>/clr</code>.</li>
  <li>Oh, and this just in:  if I call a static Entity member function, same deal.  If I move said static function outside of the class, same deal.  But, if I move that function to another module, it's fine.</li>
  </ul>
  
  <p>If I set the debugger to break on any exception, I do get something interesting:</p>
  
  <pre><code>First-chance exception at 0x7c812aeb in vstesthost.exe: Microsoft C++ exception: HRException at memory location 0x05129890..
  </code></pre>
  
  <p>There's no source code at that location, of course.  Here's the call stack:</p>
  
  <pre><code>     kernel32.dll!7c812aeb()    
      [Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]  
      kernel32.dll!7c812aeb()     
      [External Code] 
      msvcr80.dll!78158ed7()  
      msvcr80.dll!78158e34()  
      msvcr80.dll!78158047()  
      msvcr80.dll!7815850e()  
      msvcr80.dll!78158872()  
      msvcr80.dll!78158a57()  
      msvcr80.dll!78158b11()  
      ntdll.dll!7c9032a8()    
      ntdll.dll!7c90327a()    
      ntdll.dll!7c92a9ef()    
      ntdll.dll!7c90e46a()    
      kernel32.dll!7c812aeb()     
      kernel32.dll!7c812aeb()     
      kernel32.dll!7c812aeb()     
      msvcr80.dll!78139c4d()  
      msvcr80.dll!781323ff()  
      msctf.dll!74755764()    
      msctf.dll!74721557()    
      ws2_32.dll!71ab12bb()   
      ntdll.dll!7c90118a()    
      ntdll.dll!7c91b084()    
      ntdll.dll!7c90de7c()    
      ntdll.dll!7c90d04c()    
      ntdll.dll!7c90e43f()    
      kernel32.dll!7c80b713()     
  </code></pre>
  
  <p>And here's the stack trace that mstest reports - I don't get anything useful out of it.</p>
  
  <pre><code>Unable to get type SlidersTest.game_EntityMgr_test, SlidersTest. Error: System.IO.FileNotFoundException: The specified module could not be found. (Exception from HRESULT: 0x8007007E)
     at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark&amp; stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
     at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark&amp; stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
     at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark&amp; stackMark, Boolean forIntrospection)
     at System.Reflection.Assembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, StackCrawlMark&amp; stackMark)
     at System.Reflection.Assembly.LoadFrom(String assemblyFile)
     at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestExecuter.GetType(UnitTestElement unitTest, String type)
     at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestExecuter.ResolveMethods().
  </code></pre>
  
  <p>Why is fmod doing this?</p>