From 44382589e811ae68b44a480865435d4f8b97247c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Go=C5=82=C4=99biowski?= Date: Thu, 6 Feb 2025 12:19:51 +0100 Subject: [PATCH] Handling 'CoreWebView2 members cannot be accessed after the WebView2 control is disposed' --- src/Cody.UI/Controls/WebviewController.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Cody.UI/Controls/WebviewController.cs b/src/Cody.UI/Controls/WebviewController.cs index 4a5ac8c..f63cf85 100644 --- a/src/Cody.UI/Controls/WebviewController.cs +++ b/src/Cody.UI/Controls/WebviewController.cs @@ -1,3 +1,5 @@ +using Cody.Core.Common; +using Cody.Core.Logging; using Microsoft.Web.WebView2.Core; using System; using System.IO; @@ -5,8 +7,6 @@ using System.Threading.Tasks; using System.Windows; using System.Windows.Input; -using Cody.Core.Logging; -using Cody.Core.Common; namespace Cody.UI.Controls { @@ -116,6 +116,7 @@ public async Task PostWebMessageAsJson(string message) { try { + // From agent to webview. await Application.Current.Dispatcher.InvokeAsync(() => { @@ -127,6 +128,10 @@ await Application.Current.Dispatcher.InvokeAsync(() => { System.Diagnostics.Debug.WriteLine(message, "Agent PostWebMessageAsJson task canceled"); } + catch (AggregateException ex) when (ex.InnerException is InvalidOperationException inex) + { + System.Diagnostics.Debug.WriteLine(inex.Message, "AggregateException in PostWebMessageAsJson"); + } } private async Task ApplyVsCodeApiScript()