{"record":{"id":"3182209b68018601","repo":"cefsharp/CefSharp","slug":"invalid-size-must-be-greater-than-0-0","errorCode":null,"errorMessage":"Invalid size, must be greater than 0,0","messagePattern":"Invalid size, must be greater than 0,0","errorType":"validation","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"CefSharp.Wpf/ChromiumWebBrowser.cs","lineNumber":1977,"sourceCode":"        {\n            //We maintain a manual reference to the controls screen location\n            //(relative to top/left of the screen)\n            browserScreenLocation = GetBrowserScreenLocation();\n        }\n\n        /// <summary>\n        /// Create the underlying CefBrowser instance with the specified <paramref name=\"initialSize\"/>.\n        /// This method should only be used in instances where you need the browser\n        /// to load before it's attached to the Visual Tree. \n        /// </summary>\n        /// <param name=\"parentWindowHwndSource\">HwndSource for the Window that will host the browser.</param>\n        /// <param name=\"initialSize\">initial size</param>\n        /// <returns>Returns false if browser already created, otherwise true.</returns>\n        public bool CreateBrowser(HwndSource parentWindowHwndSource, Size initialSize)\n        {\n            if (initialSize.IsEmpty || initialSize.Equals(new Size(0, 0)))\n            {\n                throw new Exception(\"Invalid size, must be greater than 0,0\");\n            }\n\n            source = parentWindowHwndSource;\n\n            if (!CreateOffscreenBrowser(initialSize))\n            {\n                return false;\n            }\n\n            RoutedEventHandler handler = null;\n            handler = (sender, args) =>\n            {\n                Loaded -= handler;\n\n                //If the browser has finished rendering before we attach to the Visual Tree\n                //then ask for a new frame to be generated\n                var host = this.GetBrowserHost();\n                if (host != null)","sourceCodeStart":1959,"sourceCodeEnd":1995,"githubUrl":"https://github.com/cefsharp/CefSharp/blob/16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec/CefSharp.Wpf/ChromiumWebBrowser.cs#L1959-L1995","documentation":"CreateBrowser explicitly creates the underlying offscreen CEF browser before the control is attached to the visual tree. CEF requires a non-zero initial size to allocate its backing surface. Passing Size.Empty or a size equal to (0, 0) is rejected because a zero-area browser window is invalid.","triggerScenarios":"Calling CreateBrowser(parentWindowHwndSource, initialSize) where initialSize is new Size(0,0), default(Size), or a Size whose Width or Height is zero. Common when the host window has not yet been measured/arranged.","commonSituations":"Invoking CreateBrowser inside a Window constructor or an early Loaded handler before the layout pass has assigned actual dimensions. Computing size from ActualWidth/ActualHeight that are still 0 at call time.","solutions":["Defer the CreateBrowser call until after the host window has completed its layout pass — use ContentRendered or SizeChanged with non-zero dimensions.","Pass an explicit positive size, e.g. new Size(800, 600), instead of relying on measured values that may still be zero.","Check initialSize.Width > 0 && initialSize.Height > 0 before calling CreateBrowser."],"exampleFix":"// before\nbrowser.CreateBrowser(source, new Size(window.ActualWidth, window.ActualHeight));\n\n// after — guard with a fallback\nvar w = window.ActualWidth > 0 ? window.ActualWidth : 800;\nvar h = window.ActualHeight > 0 ? window.ActualHeight : 600;\nbrowser.CreateBrowser(source, new Size(w, h));","handlingStrategy":"validation","validationCode":"if (initialSize.IsEmpty || initialSize.Width <= 0 || initialSize.Height <= 0)\n{\n    throw new ArgumentException(\n        $\"initialSize must be positive, got {initialSize}\",\n        nameof(initialSize));\n}\n// safe to call now\nbrowser.CreateBrowser(source, initialSize);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never call CreateBrowser from a Window constructor or Loaded handler — defer to ContentRendered or SizeChanged.","Always provide a positive fallback size when computing from ActualWidth/ActualHeight.","Check Width > 0 && Height > 0 before the call."],"tags":["wpf","browser-creation","size","validation"],"backgroundTag":null,"analyzedSha":"16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec","analyzedAt":"2026-08-13T19:57:05.828Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}