Possible cause of error code 1719 or 1723 when installing a 64-bit MSI

I have heard from a few people in the past who have run into setup failures with error code 1719 or 1723 while installing the 64-bit version of the .NET Framework on a 64-bit version of Windows.  I want to describe the underlying issue in a little more detail and provide a couple of possible workarounds in case you run into this type of issue in the future.

How to diagnose this issue

If you are encountering this issue, you will see one of the following errors in the verbose MSI log file for the failing installation:

MSI (s) (DC:FC) [12:34:56:023]: Invoking remote custom action. DLL: C:\Windows\Installer\MSICE44.tmp, Entrypoint: SchedSecureObjects
MSI (s) (DC:B8) [12:34:56:024]: Generating random cookie.
MSI (s) (DC:B8) [12:34:56:051]: Created Custom Action Server with PID 1884 (0x75C).
MSI (s) (DC:98) [12:34:56:092]: Running as a service.
MSI (s) (DC:98) [12:34:56:094]: Custom Action Server rejected - Wrong Context
MSI (s) (DC:B8) [12:34:56:097]: CA Server Process has terminated.
Action start 12:34:56: SchedSecureObjects_x64.
MSI (s) (DC:94) [12:34:56:098]: Note: 1: 1719
CustomAction SchedSecureObjects_x64 returned actual error code 1601 (note this may not be 100% accurate if translation happened inside sandbox)
MSI (s) (DC:94) [12:34:56:738]: Product: Microsoft .NET Framework 4 Client Profile -- Error 1719. The Windows Installer Service could not be accessed. This can occur if the Windows Installer is not correctly installed. Contact your support personnel for assistance.

MSI (s) (B4:74) [12:34:56:098]: Note: 1: 1723
CustomAction SchedSecureObjects_x64 returned actual error code 1157 (note this may not be 100% accurate if translation happened inside sandbox)
MSI (s) (B4:74) [12:34:56:738]: Product: Microsoft .NET Framework 4 Client Profile -- Error 1723. There is a problem with this Windows Installer package. A DLL required for this install to complete could not be run. Contact your support personnel or package vendor.  Action SchedSecureObjects_x64, entry: SchedSecureObjects, library: C:\Windows\Installer\MSIE8C8.tmp

The underlying problem in this scenario is that Windows Installer is incorrectly configured to run in 32-bit mode.  64-bit custom actions cannot run in 32-bit mode, and so any 64-bit MSI that includes a 64-bit custom action (including, but not limited to, all 64-bit versions of the .NET Framework starting with 2.0) will fail in this way the first time it tries to run a 64-bit custom action. 

How to work around this issue

If you are encountering this issue, you can remove the following registry value to prevent Windows Installer from trying to run 64-bit custom actions in 32-bit mode:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\msiserver]
WOW64=1

If the above registry value does not exist on your computer, then there is another possible root cause and workaround described in this blog post from Robert Flaming.