{"record":{"id":"71876311df402148","repo":"dotnet/wpf","slug":"the-operation-completed-successfully","errorCode":null,"errorMessage":"The operation completed successfully.","messagePattern":"The operation completed successfully\\.","errorType":"exception","errorClass":"Win32Exception","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/Dispatcher.cs","lineNumber":2129,"sourceCode":"                    result = UnsafeNativeMethods.GetMessageW(ref msg,\n                                                             new HandleRef(this, hwnd),\n                                                             minMessage,\n                                                             maxMessage);\n                }\n                else\n                {\n                    int intResult;\n\n                    messagePump.GetMessageW(\n                        ref msg,\n                        hwnd,\n                        minMessage,\n                        maxMessage,\n                        out intResult);\n\n                    if (intResult == -1)\n                    {\n                        throw new Win32Exception();\n                    }\n                    else if (intResult == 0)\n                    {\n                        result = false;\n                    }\n                    else\n                    {\n                        result = true;\n                    }\n                }\n            }\n            finally\n            {\n                if (messagePump != null) Marshal.ReleaseComObject(messagePump);\n            }\n\n            return result;\n        }","sourceCodeStart":2111,"sourceCodeEnd":2147,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/Dispatcher.cs#L2111-L2147","documentation":"Dispatcher throws Win32Exception when a Win32 API call it made returns -1, meaning the underlying OS call failed. The exception has no specific error code set by this code path, so the default message 'The operation completed successfully.' appears because Win32Exception formats HRESULT/Win32 error 0 (S_OK) when no error code is provided. This makes the message misleading - the operation actually failed at the Win32 level.","triggerScenarios":"A Win32 API invoked by Dispatcher (with an out int result) returns -1, e.g. during message-pump or timer-related native interop in the WndProc/dispatch pipeline; the code then throws new Win32Exception() with no error code.","commonSituations":"Native OS resource exhaustion (e.g. too many window handles), running in unusual desktop/session contexts (services, session 0), or OS-level failures during window message processing in WPF apps.","solutions":["Inspect the inner state/logs of the failing Win32 call; if possible, capture GetLastError immediately at the failure point via diagnostics or a debugger","Ensure the app is running in an interactive desktop session with a valid message queue (not a service without a desktop)","Check for handle/GDI object leaks that exhaust window-station resources","Update .NET/WPF to the latest patch - several Dispatcher Win32 interop failure modes have been fixed"],"exampleFix":"// before\nif (intResult == -1)\n{\n    throw new Win32Exception();\n}\n// after\nif (intResult == -1)\n{\n    int error = Marshal.GetLastWin32Error();\n    throw new Win32Exception(error, $\"Win32 call failed with error {error}\");\n}","handlingStrategy":"try-catch","validationCode":"// No pre-call validation possible; ensure an interactive desktop session\nbool hasDesktop = Environment.UserInteractive;","typeGuard":null,"tryCatchPattern":"try\n{\n    dispatcher.Invoke(() => work());\n}\ncatch (Win32Exception ex)\n{\n    logger.LogError(ex, \"Dispatcher Win32 call failed (error {Code})\", ex.ErrorCode);\n    // surface a retry or fallback UI path\n}","preventionTips":["Run WPF apps in an interactive session, not session 0 services","Monitor and fix GDI/handle leaks","Keep .NET/WPF runtime patched","Capture GetLastError via diagnostics for real error codes"],"tags":["win32","interop","dispatcher","wpf"],"backgroundTag":"internal-invariant-violation","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"}