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
I've been trying to get AddHostObjectToScript to work in my UWP application. But it always fails with Exception. I tried using the WPF example browser and it worked #494.
The UWP program exception message is as follows:
System.Exception: 'The group or resource is not in the correct state to perform the requested operation.
The group or resource is not in the correct state to perform the requested operation.'
Importance
Blocking. My app's basic functions are not working due to this issue.
4.Change the code to the following in MainPage.xml.cs:
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
InitializeWebView2();
}
private async void InitializeWebView2()
{
await webView2.EnsureCoreWebView2Async();
webView2.CoreWebView2.AddHostObjectToScript("bridge", new Bridge());
}
}
// Bridge and BridgeAnotherClass are C# classes that implement IDispatch and works with AddHostObjectToScript.
[ClassInterface(ClassInterfaceType.AutoDual)]
[ComVisible(true)]
public class BridgeAnotherClass
{
// Sample property.
public string Prop { get; set; } = "Example";
}
[ClassInterface(ClassInterfaceType.AutoDual)]
[ComVisible(true)]
public class Bridge
{
public string Func(string param)
{
return "Example: " + param;
}
public BridgeAnotherClass AnotherObject { get; set; } = new BridgeAnotherClass();
// Sample indexed property.
[System.Runtime.CompilerServices.IndexerName("Items")]
public string this[int index]
{
get { return m_dictionary[index]; }
set { m_dictionary[index] = value; }
}
private Dictionary<int, string> m_dictionary = new Dictionary<int, string>();
}
5.Debug and run the program, and the final program raises an exception as shown:
Repros in Edge Browser
Yes, issue can be reproduced in the corresponding Edge version
Regression
No, this never worked
Last working version (if regression)
No response
The text was updated successfully, but these errors were encountered:
What happened?
I've been trying to get AddHostObjectToScript to work in my UWP application. But it always fails with Exception. I tried using the WPF example browser and it worked #494.
The UWP program exception message is as follows:
Importance
Blocking. My app's basic functions are not working due to this issue.
Runtime Channel
Stable release (WebView2 Runtime)
Runtime Version
Microsoft Edge WebView2 Runtime 129.0.2792.79
SDK Version
Microsoft.UI.XAML v2.8.6 & Microsoft.Web.WebView2(>=1.0.1264.42)
Framework
WinUI2/UWP
Operating System
Windows 11
OS Version
23H2 , OS build 22631.4169
Repro steps
1.Create a UWP sample application using Visual Studio 2022
2.Add the Microsoft.UI.XAML v2.8.6 NuGet package to the sample application
3.Add the use of WebView2 controls to the MainPage.xaml code file
e.g:
4.Change the code to the following in MainPage.xml.cs:
5.Debug and run the program, and the final program raises an exception as shown:
Repros in Edge Browser
Yes, issue can be reproduced in the corresponding Edge version
Regression
No, this never worked
Last working version (if regression)
No response
The text was updated successfully, but these errors were encountered: