You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- .NET MAUI CommunityToolkit: 10.0.0
- OS: Windows 11 Pro 24H2
- .NET MAUI: 9.0.101
Anything else?
You do not need to specify a Bing Maps key to observe the error.
The exception thrown is
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
WinRT information: ExecuteScriptAsync(): Failed because a valid CoreWebView2 is not present. Make sure one was created, for example by calling EnsureCoreWebView2Async() API.
An exception of type 'System.InvalidOperationException' occurred in System.Private.CoreLib.dll but was not handled in user code
WinRT information: ExecuteScriptAsync(): Failed because a valid CoreWebView2 is not present. Make sure one was created, for example by calling EnsureCoreWebView2Async() API.
A method was called at an unexpected time.
To fix this, I believe the CallJSMethod should be modified to include a call to webView2.EnsureCoreWebView2Async() before attempting to call a JasvaScript method. As shown below:
static async Task CallJSMethod(FrameworkElement platformWebView, string script)
{
if (platformWebView is WebView2 webView2)
{
+ await webView2.EnsureCoreWebView2Async();
var tcs = new TaskCompletionSource();
webView2.DispatcherQueue.TryEnqueue(async () =>
{
await webView2.ExecuteScriptAsync(script);
tcs.SetResult();
});
await tcs.Task;
}
}
I will submit a PR in the next day or so, with the supplied fix.
The text was updated successfully, but these errors were encountered:
Is there an existing issue for this?
Did you read the "Reporting a bug" section on Contributing file?
Current Behavior
When running the CommunityToolkit.Maui.Sample application and selecting the Views / Map Basic Page, a System.InvalidOperationException is thrown.
Expected Behavior
The Views / Map Basic Page should be displayed, showing the Map View.
Steps To Reproduce
Link to public reproduction project repository
https://github.com/CommunityToolkit/Maui/
Environment
Anything else?
You do not need to specify a Bing Maps key to observe the error.
The exception thrown is
To fix this, I believe the CallJSMethod should be modified to include a call to
webView2.EnsureCoreWebView2Async()
before attempting to call a JasvaScript method. As shown below:I will submit a PR in the next day or so, with the supplied fix.
The text was updated successfully, but these errors were encountered: