title: Blazor javascript interop - object conversion from js to .NET
body: <p>I am using Blazor javascript interop (js call to .NET), as in</p>
  
  <pre><code>//js
  dotNetObjRef.invokeMethodAsync("DotNetMethod", jsObject);
  ---------------------------------------------------------
  //C#
  [JSInvokable]
  public void DotNetMethod(object jsObject)
  {
      Console.WriteLine($"jsObject type is {jsObject.GetType()}");
  }
  </code></pre>
  
  <p>in the browser console, I get:</p>
  
  <pre><code>'jsObject type is SimpleJson.JsonObject'
  </code></pre>
  
  <p>Now I would like to cast jsObject to a concrete SimpleJson.JsonObject, as in</p>
  
  <pre><code>[JSInvokable]
  public void DotNetMethod(object jsObject)
  {
      JsonObject jsObject = (JsonObject)jsObject; //error
  }
  </code></pre>
  
  <p>but all my trials using C# community implementations of SimpleJson (like <a href="https://github.com/facebook-csharp-sdk/simple-json" rel="nofollow noreferrer">https://github.com/facebook-csharp-sdk/simple-json</a>) fail complaining that the cast is not valid.</p>
  
  <p>As a workaround I go through strings:</p>
  
  <pre><code>//js
  dotNetObjRef.invokeMethodAsync("DotNetMethod", JSON.stringify(jsObject));
  .
  //C#
  [JSInvokable]
  public void DotNetMethod(string jsObjectJSON)
  {
      JsonObject jsObject = SimpleJson.DeserializeObject&lt;JsonObject&gt;(jsObjectJSON);
  }
  </code></pre>
  
  <p>Does anyone know whether it is possible (and how) to use the received jsObject directly, i.e. avoiding the serialization/deserialization (and without reflection)?</p>