{"record":{"id":"d8fc070e6f9ffda1","repo":"stride3d/stride","slug":"invalid-window-handle","errorCode":null,"errorMessage":"Invalid window handle.","messagePattern":"Invalid window handle\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/presentation/Stride.Core.Presentation.Wpf/Interop/NativeHelper.cs","lineNumber":623,"sourceCode":"        public const uint WINEVENT_INCONTEXT = 4;\n        public const uint WINEVENT_OUTOFCONTEXT = 0;\n        // ReSharper restore InconsistentNaming\n\n        #endregion // Constants\n\n        public static bool SetCursorPos(Point pt)\n        {\n            return SetCursorPos((int)pt.X, (int)pt.Y);\n        }\n\n        /// <summary>\n        /// Enables window minimize button\n        /// </summary>\n        /// <param name=\"handle\">Native window handle</param>\n        public static void EnableMinimizeButton(IntPtr handle)\n        {\n            if (handle == IntPtr.Zero)\n                throw new InvalidOperationException(\"Invalid window handle.\");\n\n            SetWindowLong(handle, GWL_STYLE, GetWindowLong(handle, GWL_STYLE) | WS_MINIMIZEBOX);\n        }\n\n        /// <summary>\n        /// Disables window minimize button\n        /// </summary>\n        /// <param name=\"handle\">Native window handle</param>\n        public static void DisableMinimizeButton(IntPtr handle)\n        {\n            if (handle == IntPtr.Zero)\n                throw new InvalidOperationException(\"Invalid window handle.\");\n\n            SetWindowLong(handle, GWL_STYLE, GetWindowLong(handle, GWL_STYLE) & ~WS_MINIMIZEBOX);\n        }\n\n        /// <summary>\n        /// Enables window maximize button","sourceCodeStart":605,"sourceCodeEnd":641,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Presentation.Wpf/Interop/NativeHelper.cs#L605-L641","documentation":"NativeHelper.EnableMinimizeButton throws this InvalidOperationException when the native window handle is IntPtr.Zero, because SetWindowLong/GetWindowLong would otherwise operate on a null handle with no meaningful result. The library validates the handle before touching Win32 style flags.","triggerScenarios":"Calling NativeHelper.EnableMinimizeButton(IntPtr.Zero); passing a Handle property of a Window or control that has not yet been created (source initialized).","commonSituations":"Calling the helper in a window constructor before the HWND exists; passing IntPtr.Zero as a default/uninitialized value; interop with a window that failed to load.","solutions":["Wait until the window handle exists (override OnSourceInitialized or use the Loaded event) before calling","Check handle != IntPtr.Zero before calling","Resolve the handle with WindowInteropHelper.EnsureHandle() or Handle property first"],"exampleFix":"// before\nNativeHelper.EnableMinimizeButton(window.Handle);\n// after\nif (window.Handle != IntPtr.Zero)\n    NativeHelper.EnableMinimizeButton(window.Handle);","handlingStrategy":"validation","validationCode":"if (handle == IntPtr.Zero)\n    return; // or defer until OnSourceInitialized","typeGuard":"bool HasHandle(IntPtr h) => h != IntPtr.Zero;","tryCatchPattern":"try { NativeHelper.EnableMinimizeButton(handle); }\ncatch (InvalidOperationException ex) { Log.Warn(\"No valid window handle\", ex); }","preventionTips":["Call style helpers from OnSourceInitialized/Loaded, not constructors","Never pass IntPtr.Zero defaults to interop helpers","Use WindowInteropHelper.EnsureHandle() to force handle creation","Assert handle validity in a shared helper before P/Invoke"],"tags":["wpf","interop","win32","window-handle"],"backgroundTag":"invalid-argument-value","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}