Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

198
Vistas
How to receive JavaScript object in C# when using Webview2 without using JSON

I am playing with Webview2 and tried to pass JavaScript object to C# method of registered Host Object, but I do not know how to retrieve its content.

public object[] TestCall(string arg1, object arg2)
{
    // arg2.item1 // This don't work
    // Including arg2 in array will return it back to JavaScript, so it is stored some where
    return new List<object>() { "item1", "item2", 123, false, arg1, arg2 }.ToArray();
}
// await window.chrome.webview.hostObjects.dotNetObject.TestCall("Hello world", { item1: "value1", item2: 1234 });

I tried to look up official C# samples, but none demonstrated how to pass JavaScript object into method of HostObject.

I had worked around this by using JSON to exchange data between C# and JavaScript.

Yet I'm still puzzled.

My question:

How do I pass any JavaScript object into method of HostObject without stringify it to JSON?

Is there anyway to get content out of JS object I received in arg2?

What I tried

  • I used System.Runtime.InteropServices.Marshal.GetIDispatchForObject(arg2); to get a pointer.

    But I do not know what to do with it, since I do not have knowledge of COM or IDispatch.

  • I tried casting it to ExpandoObject, Invalid cast

  • I tried casting it to dynamic, successful, but ((dynamic)arg2).item1 throws NotImplementedException

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda