title: Can't instantiate a COM object written in C# from VBA (VB6 ok)
body: <p>Using VS 2008, here is my COM object</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Text;
  using System.Runtime.InteropServices;
  using System.Windows.Forms;
  
  namespace TestCom
  {    
      [Guid("9E5E5FB2-219D-4ee7-AB27-E4DBED8E123E")]
      [ClassInterface(ClassInterfaceType.AutoDual)]
      [ProgId("Test9.COMINT")]
      public class TestComClass  
      { 
          public void Init(string userid, string password)
          {
              MessageBox.Show(string.Format("{0}/{1}", userid, password));
          }       
      }
  }
  </code></pre>
  
  <p>If I build this and register it on a production machine as follows</p>
  
  <pre><code>REGASM /CODEBASE TESTCOM.DLL
  </code></pre>
  
  <p>From a simple VB6 app this works fine</p>
  
  <pre><code>Private Sub Form_Load()
    Dim o As Object
    Set o = CreateObject("Test9.COMINT")
    o.Init "A", "B" 
  End Sub
  </code></pre>
  
  <p>This exact same code called from VBA in Excel gives  </p>
  
  <blockquote>
    <p>"automation error" (0x80131700)</p>
  </blockquote>
  
  <p>Everything works fine on a development machine, just not on a production machine with just .NET and MS Office installed.</p>
  
  <h2>Update</h2>
  
  <p>I think this is something to do with the .NET framework not being initialized properly, when running under Excel. If I use Filemon I can see it skip around looking for MSCORWKS.DLL. When I call the same object from VBScript, it finds MSCorwks.dll fine.</p>
  
  <p>When I called <code>CorBindToCurrentRunTime</code> from VBA to try to forcibly load the CLR, interestingly I get the exact same <code>HRESULT (0x80131700)</code> as when I do <code>CreateObject()</code> in VBA.</p>
  
  <p>Therefore I think it is a framework initialization issue.</p>