dotnet/wpf · error · Win32Exception
Win32Exception (native SystemParametersInfo failure…
Error message
Win32Exception (native SystemParametersInfo failure retrieving MouseVanish)
What it means
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.
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.
Example fix
// before
bool vanish = SystemParameters.MouseVanish;
// after
bool vanish = SystemInformation.TerminalServerSession
? false
: ReadMouseVanishWithFallback(); // try/catch(Win32Exception) => false Defensive patterns
Strategy: fallback
Validate before calling
bool sessionOk = !SystemInformation.TerminalServerSession && Environment.UserInteractive; // SPI_GETMOUSEVANISH is commonly unsupported in remote sessions; skip when sessionOk is false
Try / catch
bool vanish;
try { vanish = SystemParameters.MouseVanish; }
catch (Win32Exception)
{
vanish = false; // safe default: pointer does not vanish
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: RDP/Citrix sessions lacking mouse-vanish support; automation harnesses running headless; older or stripped-down Windows editions.
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/083898667500037e.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemParameters.cs:208
/// </summary>
// If this becomes public, it will need a matching ResourceKey.
internal static bool MouseVanish
{
get
{
lock (_cacheValid)
{
while (!_cacheValid[(int)CacheSlot.MouseVanish])
{
_cacheValid[(int)CacheSlot.MouseVanish] = true;
if (UnsafeNativeMethods.SystemParametersInfo(NativeMethods.SPI_GETMOUSEVANISH, 0, ref _mouseVanish, 0))
{
}
else
{
_cacheValid[(int)CacheSlot.MouseVanish] = false;
throw new Win32Exception();
}
}
}
return _mouseVanish;
}
}
#endregion
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
private static SystemResourceKey CreateInstance(SystemResourceKeyID KeyId)
{
return new SystemResourceKey(KeyId);
}
#region Accessibility Keys
View on GitHub (pinned to 81131a70a4)