title: Reg free COM interop with C#, possible?
body: <p>Is it possible to use registration free COM with Dotnet interop and C#? If so how does one add a reference to the COM object in the C# project?</p>
  
  <p>I have a reg free ATL COM server dll with an embedded manifest and two test clients, one cpp the other c#. The cpp client correctly references the COM object using an import statement and either</p>
  
  <pre><code>#pragma comment(linker, "\"/manifestdependency:type='win32' name='TestComSvr2' version='1.0.0.0'\"")
  </code></pre>
  
  <p>or setting 'Additional Manifest Dependencies' to "type='win32' name='TestComSvr1' version='1.0.0.0'" under Linker->Manifest File options, after which the cpp client will run correctly just so long as the COM component is in the same directory.</p>
  
  <p>The c# client though refuses to play at all.</p>
  
  <p>Attempting to add a file reference to either the unregistered COM component dll or unregistered tlb results in the error:</p>
  
  <blockquote>
    <p>"A reference to 'blah blah' could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component".</p>
  </blockquote>
  
  <p>Registering just the type library with 'regtlib TestComSvr' and then creating either a file or COM reference to that results in the c# project failing to build with:</p>
  
  <blockquote>
    <p>"Error loading type library/Dll. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY))".</p>
  </blockquote>
  
  <p>Registering the COM component and creating a reference normally in the c# project, setting the reference to Isolated, building the c# project then unregistering the component and running the c# project results in this exception:</p>
  
  <blockquote>
    <p>Retrieving the COM class factory for component with CLSID {B1D0A80F-0050-4856-BACD-87D664E58CBE} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).</p>
  </blockquote>
  
  <p>Note: Even if this worked it wouldn't be a useful case anyway, since ultimately it still requires registration of the component, I just tested it for thoroughness.</p>
  
  <p>So far the only way I've been able to reference the COM object from C# at all is by registering the COM object itself, which of course utterly defeats the point since then it isn't reg-free at all.</p>
  
  <p>Anyone got any ideas?</p>
  
  <p>(This is on WinXP with VS2010 sp1).</p>