{"record":{"id":"083898667500037e","repo":"dotnet/wpf","slug":"win32exception-native-systemparametersinfo-failure-083898","errorCode":null,"errorMessage":"Win32Exception (native SystemParametersInfo failure retrieving MouseVanish)","messagePattern":"Win32Exception \\(native SystemParametersInfo failure retrieving MouseVanish\\)","errorType":"exception","errorClass":"Win32Exception","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemParameters.cs","lineNumber":208,"sourceCode":"        /// </summary>\n        // If this becomes public, it will need a matching ResourceKey.\n        internal static bool MouseVanish\n        {\n            get\n            {\n                lock (_cacheValid)\n                {\n                    while (!_cacheValid[(int)CacheSlot.MouseVanish])\n                    {\n                        _cacheValid[(int)CacheSlot.MouseVanish] = true;\n\n                        if (UnsafeNativeMethods.SystemParametersInfo(NativeMethods.SPI_GETMOUSEVANISH, 0, ref _mouseVanish, 0))\n                        {\n                        }\n                        else\n                        {\n                            _cacheValid[(int)CacheSlot.MouseVanish] = false;\n                            throw new Win32Exception();\n                        }\n                    }\n                }\n\n                return _mouseVanish;\n            }\n        }\n\n        #endregion\n\n        [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]\n        private static SystemResourceKey CreateInstance(SystemResourceKeyID KeyId)\n        {\n            return new SystemResourceKey(KeyId);\n        }\n\n        #region Accessibility Keys\n","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemParameters.cs#L190-L226","documentation":"The MouseVanish property calls SystemParametersInfo(SPI_GETMOUSEVANISH); if it returns false, the cache slot is cleared and a Win32Exception is thrown. It indicates the OS could not report whether the pointer hides while typing. Thrown from the public getter on the first, uncached read.","triggerScenarios":"First access of SystemParameters.MouseVanish in an environment where SPI_GETMOUSEVANISH fails - notably Terminal Services/remote sessions where the parameter is unsupported, or pointer settings unreadable.","commonSituations":"RDP/Citrix sessions lacking mouse-vanish support; automation harnesses running headless; older or stripped-down Windows editions.","solutions":["Retry the property; the cache slot was invalidated so a subsequent read re-issues the SPI call.","Wrap in try/catch(Win32Exception) and default to false (pointer not vanishing).","Test on a physical, interactive session; treat remote-session environments as the likely culprit.","If supporting remotes is required, pre-check the session type (SystemInformation.TerminalServerSession) and skip the read."],"exampleFix":"// before\nbool vanish = SystemParameters.MouseVanish;\n// after\nbool vanish = SystemInformation.TerminalServerSession\n    ? false\n    : ReadMouseVanishWithFallback(); // try/catch(Win32Exception) => false","handlingStrategy":"fallback","validationCode":"bool sessionOk = !SystemInformation.TerminalServerSession && Environment.UserInteractive;\n// SPI_GETMOUSEVANISH is commonly unsupported in remote sessions; skip when sessionOk is false","typeGuard":null,"tryCatchPattern":"bool vanish;\ntry { vanish = SystemParameters.MouseVanish; }\ncatch (Win32Exception)\n{\n    vanish = false; // safe default: pointer does not vanish\n}","preventionTips":["Pre-check SystemInformation.TerminalServerSession before reading MouseVanish","Provide a hard default rather than crashing on unsupported SPI queries","Retry once; the cache slot invalidation enables a fresh query","Log the environment (session type, OS) when this fires"],"tags":["wpf","win32","systemparametersinfo","interop"],"backgroundTag":"native-systemparametersinfo-failure","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"}