Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

126
Views
WebView2 AddHostObjectToScript no puede acceder a la función con parámetros

He estado siguiendo la documentación de webview2 en el sitio web oficial de Microsoft, pero encontré un problema que no estoy seguro de cómo solucionar.

He agregado un objeto .NET usando AddHostObjectToScript y funciona siempre que la función no tenga parámetros. Al llamar a la función de objeto que tiene un parámetro en JS, sigo recibiendo un error de "el parámetro es incorrecto".

Así es como llamo a los objetos host en la aplicación angular:

result = await window?.chrome?.webview?.hostObjects.bridge.Func("John");

y esto es de mi aplicación WinUI 3.0:

 [ComVisible(true)] public class Bridge { public string Func(string param) { return "Example: " + param; } public string Sample() { return "Example: "; } 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>(); } public sealed partial class WebViewPage : Page { public WebViewViewModel ViewModel { get; } public WebViewPage() { ViewModel = Ioc.Default.GetService<WebViewViewModel>(); InitializeComponent(); ViewModel.WebViewService.Initialize(webView); webView.WebMessageReceived += getMsg; InitializeAsync(); } async void InitializeAsync() { await webView.EnsureCoreWebView2Async(); var interop = webView.CoreWebView2.As<ICoreWebView2Interop>(); interop.AddHostObjectToScript("bridge", new Bridge()); }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Actualmente, WebView2 tiene un problema en el que la interfaz de interoperabilidad AddHostObjectToScript de la API de WinRT no funciona bien con objetos .NET. Este es un error en WebView2.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!