title: How to use a COM-Wrapper?
body: <p>Question:</p>
  
  <p>I have to work (in VB.NET) with an application (Aperture)'s  OLE automation via COM-Wrapper.</p>
  
  <p>Currently, I switch off option strict, and do it like this (using late-binding):</p>
  
  <pre><code>Dim m_Aperture As Object = CreateObject("Aperture.Application")
  Dim m_Project As Object = m_Aperture.Project
  </code></pre>
  
  <p>You see the problem, everything is an object, no intellisense, etc.<br />
  Very bad.</p>
  
  <p>Since I want to get intellisense and and compile-time checking to work, I tried to automatically create a COM-wrapper like this:</p>
  
  <pre><code>"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\TlbImp.exe" OEAPP.TLB /out:Aperture.dll
  </code></pre>
  
  <p>So far worked splendidly, it created the wrapper, I can use intellisense on it (return types are all of type dynamic though).</p>
  
  <p><img src="https://i.stack.imgur.com/n0Sxq.png" alt="enter image description here"></p>
  
  <p>So I tried to rewrite just the above sample code (now in C#):</p>
  
  <p>First attempt was:</p>
  
  <pre><code>Aperture.OEAppClass app = new Aperture.OEAppClass();
  </code></pre>
  
  <p>But I got this compiler error:</p>
  
  <pre><code>Interop-Type Aperture.OEAppClass cannot be embedded. Use interface instead.
  </code></pre>
  
  <p>So i tried to do it via interface:</p>
  
  <pre><code>Aperture.OEApp Ap = (Aperture.OEApp)Microsoft.VisualBasic.Interaction.CreateObject("Aperture.Application");
  </code></pre>
  
  <p>That got me an exception at runtime</p>
  
  <pre><code>InvalidCastException
  "System.__ComObject" cannot be converted into interface type "Aperture.OEApp".
  0x80010105 (RPC_E_SERVERFAULT)).
  </code></pre>
  
  <p>So I tried to figure out the interface type using </p>
  
  <pre><code>dynamic Ap2 = Microsoft.VisualBasic.Interaction.CreateObject("Aperture.Application");
  </code></pre>
  
  <p>and object-inspector.</p>
  
  <p>I found out the interface is actually of type Aperture._IOEApp.
  So I used </p>
  
  <pre><code>Aperture._IOEApp Ap = (Aperture._IOEApp)Microsoft.VisualBasic.Interaction.CreateObject("Aperture.Application");
  </code></pre>
  
  <p>But now I get</p>
  
  <pre><code>InvalidCastException
  "System.__ComObject" cannot be converted into interface type "Aperture._IOEApp".
  0x80010105 (RPC_E_SERVERFAULT)).
  </code></pre>
  
  <p>Now I don't know what the problem could be anymore.</p>
  
  <p>Can anybody tell me what I do wrong ?<br />
  Or how this is supposed to work ?</p>