COMException from WPF applications after .NET Framework 4.7 is installed on Windows 7 or Windows Server 2008 R2
This article helps you resolve the problem where System.Runtime.InteropServices.COMException
occurs in Windows Presentation Framework (WPF) applications.
Original product version: .NET Framework 4.7, Windows 7 Service Pack 1, Windows Server 2008 R2 Service Pack 1
Original KB number: 4033488
Consider the following scenario:
- You have a touch device that is running Microsoft Windows 7 Service Pack 1 (SP1) or Windows Server 2008 R2 SP1.
- Some WPF applications are running on the device.
- You install the May 2017 Preview of Quality Rollup for the .NET Framework 4.6, 4.6.1, and 4.6.2 (KB 4104606) on the device.
- You then install the .NET Framework 4.7 on the device.
In this scenario, the WPF applications fail and generate error messages:
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))
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.
To work around this problem, uninstall and then reinstall the .NET Framework 4.7. Alternatively, temporarily disable the affected WPF touch component.
In Control Panel, select Uninstall a program in the Programs category.
In the list of programs, locate and select Microsoft .NET Framework 4.7, and then select Uninstall/Change.
In the .NET Framework 4.7 Maintenance wizard, select Remove.NET Framework 4.7 from this computer, and then select Next.
If the following warning window appears, select Continue.
Wait for the uninstallation to complete.
To reinstall the Microsoft .NET Framework 4.7, use one of the following methods.
- Download the web installer for the .NET Framework 4.7.
- Install the .NET Framework 4.7.
Open Windows Update.
Select Check online for updates from Windows Update.
After the search for updates is complete, select Optional Updates available.
Locate and select Microsoft .NET Framework 4.7 for Windows 7 and Windows Server 2008 R2, and then select OK.
Wait for the installation to complete.
To temporarily disable touch and stylus support, use one of the following methods.
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.
Warning
Serious problems might occur if you modify the registry incorrectly by using Registry Editor or by using another method. These problems might require that you reinstall the operating system. Microsoft can't guarantee that these problems can be solved. Modify the registry at your own risk.
- Location:
HKEY_LOCAL_MACHINE\Software\[Wow6432Node\]Microsoft\.NETFramework\AppContext\Switch.System.Windows.Input.Stylus
- Name:
DisableStylusAndTouchSupport
- Type: String
- Value:
true
- Location:
For more information about known issues in the .NET Framework 4.7, see Known issues for .NET Framework 4.7.