{"record":{"id":"918b682ac5edd5b2","repo":"dotnet/wpf","slug":"win32exception-native-systemparametersinfo-failure-918b68","errorCode":null,"errorMessage":"Win32Exception (native SystemParametersInfo failure retrieving DropShadow)","messagePattern":"Win32Exception \\(native SystemParametersInfo failure retrieving DropShadow\\)","errorType":"exception","errorClass":"Win32Exception","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemParameters.cs","lineNumber":298,"sourceCode":"        ///     Maps to SPI_GETDROPSHADOW\n        /// </summary>\n        public static bool DropShadow\n        {\n            get\n            {\n                lock (_cacheValid)\n                {\n                    while (!_cacheValid[(int)CacheSlot.DropShadow])\n                    {\n                        _cacheValid[(int)CacheSlot.DropShadow] = true;\n\n                        if (UnsafeNativeMethods.SystemParametersInfo(NativeMethods.SPI_GETDROPSHADOW, 0, ref _dropShadow, 0))\n                        {\n                        }\n                        else\n                        {\n                            _cacheValid[(int)CacheSlot.DropShadow] = false;\n                            throw new Win32Exception();\n                        }\n                    }\n                }\n\n                return _dropShadow;\n            }\n        }\n\n        /// <summary>\n        ///     Maps to SPI_GETFLATMENU\n        /// </summary>\n        public static bool FlatMenu\n        {\n\n            get\n            {\n                lock (_cacheValid)\n                {","sourceCodeStart":280,"sourceCodeEnd":316,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemParameters.cs#L280-L316","documentation":"The DropShadow property queries SPI_GETDROPSHADOW via SystemParametersInfo; failure invalidates the cache slot and throws Win32Exception. It means the OS would not report whether menu/tool window drop shadows are enabled. Raised by the public getter on first access.","triggerScenarios":"Reading SystemParameters.DropShadow when SystemParametersInfo(SPI_GETDROPSHADOW) returns false, e.g. themes disabled or unsupported on the host (server SKUs, remote sessions with visual styles off).","commonSituations":"Apps capturing UI settings at startup on servers without the Themes service; remote sessions with 'show window contents while dragging'/visual effects disabled; custom minimal OS images.","solutions":["Enable the Themes service / visual styles on the machine, then retry.","Catch Win32Exception and default to false (shadows off).","Retry the read - the next access re-queries the OS because the cache was invalidated.","Gate the read on environment checks (TerminalServerSession, theme support) and skip on hostile environments."],"exampleFix":"// before\nbool shadow = SystemParameters.DropShadow;\n// after\nbool shadow;\ntry { shadow = SystemParameters.DropShadow; }\ncatch (Win32Exception) { shadow = false; }","handlingStrategy":"try-catch","validationCode":"bool themesRunning = SystemParameters.ClientAreaAnimation is bool _; // probe cheap system params\n// or check service state of 'Themes' before reading DropShadow","typeGuard":null,"tryCatchPattern":"bool shadow;\ntry { shadow = SystemParameters.DropShadow; }\ncatch (Win32Exception ex)\n{\n    Trace.TraceWarning($\"DropShadow SPI failed: {ex.NativeErrorCode}\");\n    shadow = false;\n}","preventionTips":["Ensure the Themes service runs on target machines","Retry once - the next read re-issues the SPI call","Default to false (shadows off) on failure","Validate visual styles availability in deployment checks"],"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-22T01:17:13.364Z"}