dotnet/wpf · error · Win32Exception
Win32Exception (native SystemParametersInfo failure…
Error message
Win32Exception (native SystemParametersInfo failure retrieving DropShadow)
What it means
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.
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.
Example fix
// before
bool shadow = SystemParameters.DropShadow;
// after
bool shadow;
try { shadow = SystemParameters.DropShadow; }
catch (Win32Exception) { shadow = false; } Defensive patterns
Strategy: try-catch
Validate before calling
bool themesRunning = SystemParameters.ClientAreaAnimation is bool _; // probe cheap system params // or check service state of 'Themes' before reading DropShadow
Try / catch
bool shadow;
try { shadow = SystemParameters.DropShadow; }
catch (Win32Exception ex)
{
Trace.TraceWarning($"DropShadow SPI failed: {ex.NativeErrorCode}");
shadow = false;
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Win32Exception (native SystemParametersInfo failure…
- Win32Exception (native SystemParametersInfo failure…
- Win32Exception (native SystemParametersInfo failure…
- Win32Exception (no message; error code from GetLastError)
- new System.ComponentModel.Win32Exception(win32Error)
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/918b682ac5edd5b2.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemParameters.cs:298
/// Maps to SPI_GETDROPSHADOW
/// </summary>
public static bool DropShadow
{
get
{
lock (_cacheValid)
{
while (!_cacheValid[(int)CacheSlot.DropShadow])
{
_cacheValid[(int)CacheSlot.DropShadow] = true;
if (UnsafeNativeMethods.SystemParametersInfo(NativeMethods.SPI_GETDROPSHADOW, 0, ref _dropShadow, 0))
{
}
else
{
_cacheValid[(int)CacheSlot.DropShadow] = false;
throw new Win32Exception();
}
}
}
return _dropShadow;
}
}
/// <summary>
/// Maps to SPI_GETFLATMENU
/// </summary>
public static bool FlatMenu
{
get
{
lock (_cacheValid)
{View on GitHub (pinned to 81131a70a4)