{"record":{"id":"42bbf6c590e07ca8","repo":"dotnet/wpf","slug":"sr-penimcsxsregistrationfailed-penimcsxsregistrationfailed","errorCode":null,"errorMessage":"SR.PenImcSxSRegistrationFailed (PenImcSxSRegistrationFailed: {Penimc})","messagePattern":"SR\\.PenImcSxSRegistrationFailed \\(PenImcSxSRegistrationFailed: (.+?)\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"critical","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/Win32/UnsafeNativeMethodsPenimc.cs","lineNumber":111,"sourceCode":"        /// are available.\n        /// </summary>\n        /// <remarks>\n        /// PenIMC COM objects are only directly used (functions called on their interfaces) from inside the\n        /// PenThread.  As such, the PenThreads need to create the activation context.  The various Dispatcher\n        /// threads need not do so as they merely pass the RCWs around in manged objects and will only use\n        /// them via operations queued on their associated PenThread.\n        /// </remarks>\n        internal static void EnsurePenImcClassesActivated()\n        {\n            if (_pimcActCtxCookie == IntPtr.Zero)\n            {\n                // Register PenIMC for SxS COM for the lifetime of the thread.\n                //\n                // RegisterDllForSxSCOM returns a non-zero ActivationContextCookie if SxS registration\n                // succeeds, or IntPtr.Zero if SxS registration fails.\n                if ((_pimcActCtxCookie = RegisterDllForSxSCOM()) == IntPtr.Zero)\n                {\n                    throw new InvalidOperationException(SR.Format(SR.PenImcSxSRegistrationFailed, ExternDll.Penimc));\n                }\n\n                // Pass security mitigation switch to native PenImc code.\n                SetDisablePenImcBoundsCheckProtection(CoreAppContextSwitches.DisablePenImcBoundsCheckProtection);\n            }\n        }\n\n        /// <summary>\n        /// Deactivates the activation context for PenIMC objects.\n        /// </summary>\n        internal static void DeactivatePenImcClasses()\n        {\n            if (_pimcActCtxCookie != IntPtr.Zero)\n            {\n                if(DeactivateActCtx(0, _pimcActCtxCookie))\n                {\n                    _pimcActCtxCookie = IntPtr.Zero;\n                }","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/Win32/UnsafeNativeMethodsPenimc.cs#L93-L129","documentation":"WPF registers penimc.dll for side-by-side (SxS) COM activation at thread start via RegisterDllForSxSCOM. That native call returns IntPtr.Zero on failure, in which case EnsurePenImcClassesActivated throws InvalidOperationException with SR.PenImcSxSRegistrationFailed naming penimc. Without the registration, the threading stack required for stylus/touch input cannot be initialized.","triggerScenarios":"Creating a WPF Dispatcher/thread that initializes stylus input (TextServicesManager/PenContexts) on a machine where penimc.dll's SxS COM registration fails — e.g. missing or corrupt penimc.dll, mismatched bitness, or restricted activation context creation.","commonSituations":"Running WPF apps in stripped-down environments (servers, containers, Windows Nano) lacking penimc support, corrupted .NET/WPF installs, or 32/64-bit mismatch after framework changes.","solutions":["Verify penimc.dll exists beside PresentationCore/native components and matches the process bitness; repair the .NET runtime install if not.","Run the app on a full Windows installation with Windows Ink/Tablet PC components present.","In containers/services, disable real-time stylus/touch: set the registry key HKEY_CURRENT_USER\\Software\\Microsoft\\Wisp\\Pen\\SysEventParameters /v DisableRealTimeStylus /t REG_DWORD /d 1 (or set it for the service account).","Ensure the app is not running with a stripped activation context or security software blocking SxS registration."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"string penimc = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, IntPtr.Size == 8 ? \"penimc.dll\" : \"penimc.dll\");\nbool penimcAvailable = File.Exists(penimc) || NativeLibraryExists(\"penimc.dll\");","typeGuard":null,"tryCatchPattern":"try\n{\n    InitializeWpfDispatcher();\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"PenImc\"))\n{\n    log.Warn(\"Pen/touch input unavailable: penimc SxS registration failed. Disabling real-time stylus.\");\n    // set DisableRealTimeStylus=1 and retry without stylus support\n}","preventionTips":["Install the full .NET desktop runtime with native WPF components (not trimmed)","Match process bitness to the installed native penimc.dll","On servers/containers, pre-set DisableRealTimeStylus=1","Repair runtime installs if WPF startup throws PenImc errors"],"tags":["com-activation","stylus-input","native-interop","wpf-startup"],"backgroundTag":"module-init-failed","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}