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

199
Views
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
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!