title: CLR20R3 System.InvalidCastException from COM dll to .net
body: <p>In My C#.Net Windows Project, I am referencing vb6 COM dll (this COM dll is part of SDK which is already installed on all development and client machines) and then i created setup / installer for client machines using installshield.</p>
  
  <ul>
  <li>Development Machine : VS2012, Win7 Ultimate 64Bit, .Net 4.0.3. (project build any cpu / prefer 32 bit).</li>
  <li>Client Machine 1 &amp; 2 : client 1 .net v4.0.3, Win7 Ultimate (32bit) and client2 .net v4.0.3, Win7 Ultimate (64bit).</li>
  </ul>
  
  <p>vb6 COM dll is compiled in .Net 2.0 (so my project should be backward compatible)</p>
  
  <p>Project works fine (builds &amp; installs) on development machine, but when tried to run on client machine - I get the following error.</p>
  
  <pre>
  Problem signature:
    Problem Event Name:   CLR20r3
    Problem Signature 01: MyProject tool.exe
    Problem Signature 02: 1.0.3.0
    Problem Signature 03: 5252b033
    Problem Signature 04: MyProject tool
    Problem Signature 05: 1.0.3.0
    Problem Signature 06: 5252b033
    Problem Signature 07: 8
    Problem Signature 08: b
    Problem Signature 09: System.InvalidCastException
    OS Version:   6.1.7601.2.1.0.256.48
    Locale ID:    2057
    Additional Information 1: 0a9e
    Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
    Additional Information 3: 0a9e
    Additional Information 4: 0a9e372d3b4ad19135b953a78882e789
  
  Read our privacy statement online:
    http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409
  
  If the online privacy statement is not available, please read our privacy statement offline:
    C:\Windows\system32\en-US\erofflps.txt
  
  </pre>
  
  <p>What I Already Tried :
  - Initially I thought this error is due to CLR version mismatch of vb6 COM dll. So, i tried to compile c#.net project in .net 2.0, 3,4, 4.5 versions of .net (NO Show - same error).
  - Then I installed VS2010 (initially I was using vs2012 now both on the same dev machine) on the same machine and tried all over again (NO show - same error).
  - then I created a new empty project with vb6 COM dll only with reference's and installed on client machine it worked. Problem started when I created instance of class from vb6 COM dll in c#.net project. I also noticed when I created instance of COM class it says interface in VS2012 (alt banner window. the small popup when you move your mouse on class name). but again it works on development machine - so cant be interface issue. </p>
  
  <ul>
  <li>I thought it might be visual basic / c# issue. then I recreated the whole project in vb.net : I got following error. I got this error on my development machine while build (couldn't go further on clients).</li>
  </ul>
  
  <pre>
  Retrieving the COM class factory for component with CLSID {8F9F6324-E4E2-435A-AB66-7B766CE628AC} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
  </pre>
  
  <p>Then I looked into registry / CLSID registrations on all machines and COM is already registered.!</p>
  
  <ul>
  <li>then I re-created all of above block tests on different development machine still no show same error.</li>
  </ul>
  
  <p>I have also tried many solutions suggested on stackoverflow forum. like un-register and reregister msenv dlls. I tried in un-install and reinstall .net framework on client and development machines. </p>
  
  <p>Its been 3 weeks now. Any ideas what I can do at this stage? </p>