{"record":{"id":"e787c93b349a7d17","repo":"cefsharp/CefSharp","slug":"unexpected-failure-of-calling-cef-getzoomlevelasy-e787c9","errorCode":null,"errorMessage":"Unexpected failure of calling CEF->GetZoomLevelAsync","messagePattern":"Unexpected failure of calling CEF->GetZoomLevelAsync","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"warning","filePath":"CefSharp.Wpf/HwndHost/ChromiumWebBrowser.cs","lineNumber":1308,"sourceCode":"        {\n            if (newValue && !IsDisposed)\n            {\n                var task = this.GetZoomLevelAsync();\n                task.ContinueWith(previous =>\n                {\n                    if (previous.Status == TaskStatus.RanToCompletion)\n                    {\n                        UiThreadRunAsync(() =>\n                        {\n                            if (!IsDisposed)\n                            {\n                                SetCurrentValue(ZoomLevelProperty, previous.Result);\n                            }\n                        });\n                    }\n                    else\n                    {\n                        throw new InvalidOperationException(\"Unexpected failure of calling CEF->GetZoomLevelAsync\", previous.Exception);\n                    }\n                }, TaskContinuationOptions.ExecuteSynchronously);\n            }\n        }\n\n        /// <summary>\n        /// The title of the web page being currently displayed.\n        /// </summary>\n        /// <value>The title.</value>\n        /// <remarks>This property is implemented as a Dependency Property and fully supports data binding.</remarks>\n        public string Title\n        {\n            get { return (string)GetValue(TitleProperty); }\n            set { SetValue(TitleProperty, value); }\n        }\n\n        /// <summary>\n        /// The title property","sourceCodeStart":1290,"sourceCodeEnd":1326,"githubUrl":"https://github.com/cefsharp/CefSharp/blob/16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec/CefSharp.Wpf/HwndHost/ChromiumWebBrowser.cs#L1290-L1326","documentation":"Identical to the WPF version: after the HwndHost-based browser initializes, CefSharp calls GetZoomLevelAsync to sync the zoom level. If that task faults (browser disposed mid-call, CEF internal error), the continuation throws InvalidOperationException wrapping the original exception as InnerException.","triggerScenarios":"Fires inside OnIsBrowserInitializedChanged (HwndHost variant) when the GetZoomLevelAsync continuation sees a non-RanToCompletion status. The throw is in an ExecuteSynchronously continuation and surfaces as an unobserved task exception.","commonSituations":"HwndHost browser being disposed during or right after initialization. CEF crash during init. Race between init completion and shutdown.","solutions":["Subscribe to TaskScheduler.UnobservedTaskException at startup to observe and log without crashing.","Prevent premature disposal — ensure the HwndHost browser is not torn down during the init-completion window.","Inspect the InnerException (previous.Exception) to find the underlying CEF fault.","Upgrade CefSharp to a version with init/dispose race fixes."],"exampleFix":"// after — observe at startup\nTaskScheduler.UnobservedTaskException += (s, e) =>\n{\n    Log.Warn(\"Unobserved CEF task fault\", e.Exception?.InnerException ?? e.Exception);\n    e.SetObserved();\n};","handlingStrategy":"try-catch","validationCode":"// No pre-call validation possible — internal library continuation.\n// Observe globally:\nTaskScheduler.UnobservedTaskException += (s, e) =>\n{\n    if (e.Exception?.Message?.Contains(\"GetZoomLevelAsync\") == true)\n    {\n        Log.Warn(\"HwndHost CEF zoom sync faulted\", e.Exception.InnerException);\n        e.SetObserved();\n    }\n};","typeGuard":null,"tryCatchPattern":"// Cannot catch at call site — thrown in library-internal continuation.\n// Only surface: TaskScheduler.UnobservedTaskException\nTaskScheduler.UnobservedTaskException += (s, e) =>\n{\n    e.SetObserved();\n};","preventionTips":["Do not dispose the HwndHost browser during the init-to-zoom-sync window.","Always handle TaskScheduler.UnobservedTaskException when using CefSharp.","Upgrade CefSharp to benefit from init/dispose race fixes."],"tags":["cef","wpf-hwndhost","zoom-level","task-continuation","lifecycle"],"backgroundTag":null,"analyzedSha":"16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec","analyzedAt":"2026-08-13T19:57:05.828Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}