title: TypeLoadException in .NET assembly with embedded Interop
body: <p>I developed a .NET class library with the following characteristics:</p>
  
  <ul>
  <li>.NET 4.0, Any CPU</li>
  <li>References <code>adodb.dll</code> from the .NET Primary Interop Assembly folder</li>
  <li>Builds with <code>Embed Interop Type</code> set to true (default)</li>
  <li>Exposes an ADODB.RecordSet for consumption by COM.</li>
  </ul>
  
  <p>I expose the assembly to VBA via a VSTO AddIn. It runs fine on my machine, but on client machines my assembly throws a <code>System.TypeLoadException</code> when it tries to access the <code>Fields</code> property of a <code>RecordSet</code>.</p>
  
  <pre><code>public Recordset Test() {
      Recordset result = new Recordset();
      result.CursorLocation = CursorLocationEnum.adUseClient;
      Fields resultFields = result.Fields; // EXCEPTION THROWN HERE.
      ...
  }
  </code></pre>
  
  <p>Exception message:</p>
  
  <p><code>Could not load type 'ADODB.FieldsToInternalFieldsMarshaler' from assembly 'MyCompany.MyProduct.Interop.Com</code>.</p>
  
  <p>Failing clients: Win XP/32, Win 7/64.  Neither have local admin rights. Both have .NET 4.0</p>
  
  <hr>
  
  <p><strong><em>Update</em></strong>: <a href="https://stackoverflow.com/questions/5666265/adodbcould-not-load-type-adodb-fieldstointernalfieldsmarshaler-from-assembly">This Post</a> describes my problem. The accepted answer (late binding) did not work for me, but Bob's answer did (do not embed the Interop).</p>
  
  <p>As soon as I set <code>Embed Interop Types</code> to <code>False</code>, everything started working as If by magic.</p>
  
  <p>So my question has changed to "Why does embedding the interop not work?" I thought that was the best practice to avoid problems on client machines.</p>