"COMException" error from WPF applications after the .NET Framework 4.7 is installed on Windows 7 or Windows Server 2008 R2

Applies to: .NET Framework 4.7Windows 7 Service Pack 1Windows Server 2008 R2 Service Pack 1

Symptoms


Consider the following scenario:

In this scenario, the WPF applications fail and generate error messages that resemble the following message:

Exception type:   System.TypeInitializationException
Message:   The type initializer for 'MS.Win32.Penimc.UnsafeNativeMethods' threw an exception.
InnerException:   System.Runtime.InteropServices.COMException
Message of the inner exception: Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
 

Resolution


To resolve this problem, install the July 25, 2017, update for the .NET Framework 4.6, 4.6.1, 4.6.2, and 4.7 from the Microsoft Update Catalog.

Windows 7 SP1 and Windows Server 2008 R2 SP1

Download the stand-alone package from the Microsoft Update catalog. For more information about this update, see KB 4035510.

Windows 8.1 and Windows Server 2012 R2

Download the stand-alone package from the Microsoft Update catalog. For more information about this update, see KB 4035509.

Windows Server 2012

Download the stand-alone package from the Microsoft Update catalog. For more information about this update, see KB 4035508.

Workaround


To work around this problem, uninstall and then reinstall the .NET Framework 4.7. Alternatively, temporarily disable the affected WPF touch component.

Uninstall the .NET Framework 4.7

  1. In Control Panel, click Uninstall a program in the Programs category.
  2. In the list of programs, locate and click Microsoft .NET Framework 4.7, and then click Uninstall/Change.
  3. In the .NET Framework 4.7 Maintenance wizard, click Remove.NET Framework 4.7 from this computer, and then click Next.
  4. If the following warning window appears, click Continue.

    Warning at uninstalling .NET Framework 4.7
  5. Wait for the uninstallation to complete.

Reinstall the .NET Framework 4.7

To reinstall the Microsoft .NET Framework 4.7, use one of the following methods.

Method 1: Manually download and install the .NET Framework 4.7

  1. Download the web installer for the .NET Framework 4.7.
  2. Install the .NET Framework 4.7.

Method 2: Use Windows Update to install the .NET Framework 4.7

  1. Open Windows Update.
  2. Click Check online for updates from Windows Update.
  3. After the search for updates is complete, click Optional Updates available.

    Optional Updates available
  4. Locate and select Microsoft .NET Framework for Windows 7 and Windows Server 2008 R2, and then click OK.

    .NET Framework 4.7 in Windows Update
  5. Wait for the installation to complete.

Temporarily disable touch and stylus support for your WPF applications

To temporarily disable touch and stylus support, use one of the following methods.

Note See the "Status" section of this article for information about a permanent solution.

  • Add the following entry to the application configuration to disable touch and stylus support for WPF applications.

<runtime>

<AppContextSwitchOverrides value=" Switch.System.Windows.Input.Stylus.DisableStylusAndTouchSupport=true"/>

</runtime>

  • Apply the following registry subkey to disable touch and stylus support for WPF applications machine-global.

    Registry location: HKEY_LOCAL_MACHINE\Software\[Wow6432Node\]Microsoft\.NETFramework\AppContext\Switch.System.Windows.Input.Stylus.DisableStylusAndTouchSupport
     

    Type: String
    Value: "true"

Reference


For more information about known issues in the .NET Framework 4.7, see Known issues for .NET Framework 4.7.