{"record":{"id":"0cec6f216773c057","repo":"dotnet/wpf","slug":"throw-new-system-componentmodel-win32exception","errorCode":null,"errorMessage":"throw new System.ComponentModel.Win32Exception();","messagePattern":"throw new System\\.ComponentModel\\.Win32Exception\\(\\);","errorType":"exception","errorClass":"Win32Exception","httpStatus":null,"severity":"warning","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndMouseInputProvider.cs","lineNumber":234,"sourceCode":"                    {\n                        int nVirtualWidth  = UnsafeNativeMethods.GetSystemMetrics(SM.CXVIRTUALSCREEN);\n                        int nVirtualHeight = UnsafeNativeMethods.GetSystemMetrics(SM.CYVIRTUALSCREEN);\n                        int nVirtualLeft   = UnsafeNativeMethods.GetSystemMetrics(SM.XVIRTUALSCREEN);\n                        int nVirtualTop    = UnsafeNativeMethods.GetSystemMetrics(SM.YVIRTUALSCREEN);\n                        uint mode           = NativeMethods.GMMP_USE_DISPLAY_POINTS;\n\n                        NativeMethods.MOUSEMOVEPOINT mp_in  = new NativeMethods.MOUSEMOVEPOINT();\n                        NativeMethods.MOUSEMOVEPOINT[] mp_out = new NativeMethods.MOUSEMOVEPOINT[64];\n\n                        mp_in.x = _latestMovePoint.x;\n                        mp_in.y = _latestMovePoint.y;\n                        mp_in.time = 0;     // don't use a timestamp here, none of the timestamps we have actually work\n\n                        // get all points in the system buffer\n                        int n = UnsafeNativeMethods.GetMouseMovePointsEx((uint)(Marshal.SizeOf(mp_in)), ref mp_in, mp_out, 64, mode);\n                        if (n == -1)\n                        {\n                            throw new System.ComponentModel.Win32Exception();\n                        }\n\n                        // decide which points to return\n                        cpt = 0;\n                        bool ignore = true;\n                        for (int i = 0; i < n && cpt < points.Length; i++)\n                        {\n                            // ignore points that happened after the latest MouseMove\n                            if (ignore)\n                            {\n                                if (mp_out[i].time < _latestMovePoint.time ||\n                                    (mp_out[i].time == _latestMovePoint.time &&\n                                     mp_out[i].x == _latestMovePoint.x &&\n                                     mp_out[i].y == _latestMovePoint.y))\n                                {\n                                    ignore = false;\n                                }\n                                else","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndMouseInputProvider.cs#L216-L252","documentation":"HwndMouseInputProvider.GetIntermediatePoints calls the Win32 GetMouseMovePointsEx API to retrieve buffered mouse points for high-resolution mouse movement. When the API returns -1 it failed, and the code throws a bare Win32Exception carrying the native error code (commonly ERROR_POINT_NOT_FOUND). This breaks the retrieval of interpolated mouse points that make WPF mouse sampling smooth.","triggerScenarios":"Mouse processing requests intermediate points while GetMouseMovePointsEx fails — typically when the requested point's timestamp no longer exists in the system mouse buffer, or when the mp_in structure is stale/invalid (e.g. points requested after a long idle or screen lock).","commonSituations":"Rapid mouse movement combined with a slow UI thread so the buffer churns before the lookup; resuming from sleep/lock where timestamps in the buffer are stale; remote-desktop or virtualized input environments where the history buffer behaves differently.","solutions":["Treat the failure as non-fatal at the consumer level and degrade gracefully — intermediate points are an optimization; fall back to the last delivered mouse position.","Check the NativeErrorCode: ERROR_POINT_NOT_FOUND simply means the points aged out of the buffer and can be safely ignored.","Keep the UI thread responsive (avoid long work in mouse handlers) so requests happen while points are still in the system buffer.","If you own a modified build, wrap the GetMouseMovePointsEx call in try/catch and continue with n = 0 points."],"exampleFix":"// before\nint n = UnsafeNativeMethods.GetMouseMovePointsEx(size, ref mp_in, mp_out, 64, mode);\nif (n == -1)\n    throw new System.ComponentModel.Win32Exception();\n// after\nint n = UnsafeNativeMethods.GetMouseMovePointsEx(size, ref mp_in, mp_out, 64, mode);\nif (n == -1)\n    n = 0; // points not in buffer anymore; skip intermediate points\n","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    GetIntermediatePoints(...);\n}\ncatch (Win32Exception ex) when (ex.NativeErrorCode == 0) // or catch-all\n{\n    // intermediate points unavailable; proceed with last known position\n}","preventionTips":["Treat intermediate points as an optional optimization, never a requirement.","Keep mouse handlers fast so buffer points are still available.","Expect failures after sleep/resume and remote-desktop sessions; degrade gracefully."],"tags":["win32","mouse","interop","input"],"backgroundTag":"win32-api-call-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"}