1

I developed an installer program (c#, .Net4.0), which should Register an assembly (DLL with COMInterop) for a C++ Win32 Client on an AMD64 Architecture. The assembly DLL is of c#, .Net4.0 Code as well and build for 'AnyCPU'.

The following Code works fine on x86 architectures, but on x64 architectures it registers only at the x64 part of the registry HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID, but not at HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Classes\CLSID.

The Problem is, that the win32 client will lookup the CLSID at the Wow6432Node and fails with error 0x80040154 on startup.

If I Register with C:\Windows\Microsoft.NET\Framework\v4.0.30319>regasm "C:\WKS\DatabaseAssistant.dll" everything works fine.

  var strDll = sTargetDirBM + @"WKS\DatabaseAssistant.dll";
  RegisterDll(strDll, RegDllMode.eRegister);

  private bool RegisterDll(string sDll, RegDllMode bMode )
  {
     Assembly asm = Assembly.LoadFile(sDll);
     RegistrationServices regAsm = new RegistrationServices();

     bool bResult = false;
     if (bMode == RegDllMode.eRegister)
     {
        try
        {
           bResult = regAsm.RegisterAssembly(asm, AssemblyRegistrationFlags.SetCodeBase);
           if (bResult
              ) WriteLog(rm.GetString("strInfoRegister") + sDll);
           else WriteLog(rm.GetString("strErrRegister") + sDll);
        }
        catch (Exception exc)
        {
           Trace.WriteLine("Exception with RegisterAssembly(): " + sDll + " " + exc.Message);
           WriteLog(rm.GetString("strErrRegister") + sDll + " " + exc.Message);
        }
     }

How can I force the RegisterAssembly() to Register as well for win32 Clients (Wow6432Node)?

4
  • Possible duplicate: stackoverflow.com/questions/9407229/…
    – McNets
    Jan 5, 2017 at 15:10
  • 1
    You need to do the same thing that Regasm.exe does, have two distinct builds of your program. One that targets AnyCPU and another that targets x86. Just like Regasm.exe has two versions, the one you are using now from the Framework directory is the x86 version so it solved your problem. The one in the Framework64 directory is the x64 version. Jan 5, 2017 at 16:40
  • Not sure, if I understood @HansPassant Suggestion. I switched the Platform Target of the Installer Program from AnyCPU to x86, but there is no effect. I'm not sure, if Hans understood my aim. I don't want to use regasm. I want to Register programatically using the RegisterAssembly-Method of RegistrationServices-Class. Jan 6, 2017 at 11:11
  • @HansPassant comment solved my Problem. But pay Attention! It is not sufficient to set Platform Target to x86. This does not Change the binary. It is necessary to set Configuration Platform to x86, which has an Impact to the binary only. (find both at the BUILD tab) Thanks Hans, great job! Jan 9, 2017 at 11:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.