title: Getting Class Not registered 80041054 on class that is registered
body: <p>I'm calling CoCreateInstance from unmanaged code onto a managed class that is registered (the HKEY_CLASSES_ROOT\CLSID{xxxxx-xxxxxx-xxxxxx-xxxxx-xxxxxx-xxxxx} registry entry exists and the file is correctly loaded from another program. </p>
  
  <p>The code is below:</p>
  
  <pre><code>    HRESULT hRC;
      CoInitialize(NULL);
  
      char* sUTProgID = "My.Utilities";
  
      CLSID UTClassID;
      hRC = CLSIDFromProgID(
          _CW(sUTProgID),             // Pointer to the ProgID
          &amp;UTClassID );               // Pointer to the CLSID
      if ( S_OK != hRC )
      {
          DOTRACE((_T("    CLSIDFromProgID error 0x%X\n", hRC)));
      }
      IUnknown* pUnknown;
      hRC = CoCreateInstance(
      UTClassID,                  // Class identifier (CLSID) of the object
          0,                          // Pointer to whether object is or isn't part of an aggregate
          CLSCTX_ALL,                 // Context for running executable code
          IID_IUnknown,               // Reference to the identifier of the interface
          (void**) &amp;pUnknown);        // Address of output variable that receives the interface pointer requested in riid
      if ( S_OK != hRC )
      {
      //code makes it here with an 80040145 class not registered error
      }
  </code></pre>
  
  <p>The same code works for the other application. The code is compiled for x86 and is running on an x86 machine. </p>
  
  <p>EDIT: It's a windows XP machine so I assume UAC is out. I've logged the ClassID and it is indeed the correct one. I've also checked the ProcMon logs and it shows the registry key being accessed successfully and within the registry key the following paths are accessed:
  InProcServer32 - success
  InProcServerx86 - Name not found
  LocalServer32 - Name not found 
  InProcHandler32 - Name not found
  AppId - Name not found
  InProcServer32\ThreadingModel - success
  InProcServer32\1.0.0.0 - success
  InProcServer32\1.0.0.0\assembly - buffer overflow
  InProcServer32\1.0.0.0\assembly - success
  InProcServer32\1.0.0.0\class - success
  InProcServer32\1.0.0.0\RuntimeVersion - success
  InProcServer32\CodeBase - success (returns the file path)</p>
  
  <p>It then checks the GAC cache, then a few directories before accessing the DLL. </p>
  
  <p>CLIENT.EXE  1092    RegQueryKey HKCR\CLSID{...}    SUCCESS Query: Name
  CLIENT.EXE  1092    RegOpenKey  HKCR\CLSID{...}\InprocHandler  NAME NOT FOUND  Desired Access: Maximum Allowed
  CLIENT.EXE  1092    RegCloseKey HKCR\CLSID{9935FEE6-39FD-4EF0-87DB-8372B0992610}   SUCCESS 
  CLIENT.EXE  1092    RegOpenKey  HKLM\Software\Policies\Microsoft\Windows\App Management NAME NOT FOUND  Desired Access: Query Value
  CLIENT.EXE  1092    CreateFile  LogFile.txt </p>
  
  <p>I think it as the last log message that the error is logged. </p>
  
  <p>EDIT2: 
  Dll is registered using the following code: </p>
  
  <pre><code>            Assembly asm = Assembly.LoadFile(dll_name);
              RegistrationServices regAsm = new RegistrationServices();
              bool bResult = regAsm.RegisterAssembly(asm,   AssemblyRegistrationFlags.SetCodeBase);
  </code></pre>
  
  <p>EDIT3:
  Running CorFlags.exe on (my) failing DLL outputs:</p>
  
  <pre><code> Version   : v2.0.50727
   CLR Header: 2.5
   PE        : PE32
   CorFlags  : 11
   ILONLY    : 1
   32BIT     : 1
   Signed    : 1
  </code></pre>
  
  <p>Running the same on the EXE calling the DLL outputs:</p>
  
  <pre><code> Version   : v1.1.4322
   CLR Header: 2.0
   PE        : PE32
   CorFlags  : 9
   ILONLY    : 1
   32BIT     : 0
   Signed    : 1
  </code></pre>