title: Blazor WAsm - Can't invoke JS function which returns a value
body: <p><strong>What I want to do</strong><br/>
  I want to call a JS function which returns a value. I did it exactly as documented <a href="https://docs.microsoft.com/en-us/aspnet/core/blazor/call-javascript-from-dotnet?view=aspnetcore-3.1" rel="nofollow noreferrer">here</a>.</p>
  <p><strong>Setup</strong><br/>
  <em>C#</em></p>
  <pre class="lang-cs prettyprint-override"><code>Log.Warning(&quot;TESTESTESTTESTESTESTTESTESTEST&quot;);
  await JsRuntime.InvokeAsync&lt;bool&gt;(&quot;UtilityTest.testFunc&quot;);
  Log.Warning(&quot;TESTESTESTTESTESTESTTESTESTEST&quot;);
  </code></pre>
  <p><em>JS</em></p>
  <pre class="lang-js prettyprint-override"><code>var UtilityTest = new function () {
      this.testFunc = function () {
          console.log(&quot;[JS-TEST] testFunc&quot;);
          return true;
      };
  };
  </code></pre>
  <p><em>Logs</em></p>
  <pre><code>TESTESTESTTESTESTESTTESTESTEST
  [JS-TEST] testFunc
  crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
        Unhandled exception rendering component: An exception occurred executing JS interop: The JSON value could not be converted to System.Boolean. Path: $ | LineNumber: 0 | BytePositionInLine: 4.. See InnerException for more details.
  Microsoft.JSInterop.JSException: An exception occurred executing JS interop: The JSON value could not be converted to System.Boolean. Path: $ | LineNumber: 0 | BytePositionInLine: 4.. See InnerException for more details. ---&gt; System.Text.Json.JsonException: The JSON value could not be converted to System.Boolean. Path: $ | LineNumber: 0 | BytePositionInLine: 4. ---&gt; System.InvalidOperationException: Cannot get the value of a token type 'Null' as a boolean.
    at System.Text.Json.Utf8JsonReader.GetBoolean () &lt;0x2c89c00 + 0x00090&gt; in &lt;filename unknown&gt;:0 
    at System.Text.Json.Serialization.Converters.JsonConverterBoolean.Read (System.Text.Json.Utf8JsonReader&amp; reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) &lt;0x30ab220 + 0x00004&gt; in &lt;filename unknown&gt;:0 
    at System.Text.Json.JsonPropertyInfoNotNullable`4[TClass,TDeclaredProperty,TRuntimeProperty,TConverter].OnRead (System.Text.Json.ReadStack&amp; state, System.Text.Json.Utf8JsonReader&amp; reader) &lt;0x30a45a8 + 0x0003c&gt; in &lt;filename unknown&gt;:0 
    at System.Text.Json.JsonPropertyInfo.Read (System.Text.Json.JsonTokenType tokenType, System.Text.Json.ReadStack&amp; state, System.Text.Json.Utf8JsonReader&amp; reader) &lt;0x30a41d8 + 0x00088&gt; in &lt;filename unknown&gt;:0 
    at System.Text.Json.JsonSerializer.HandleNull (System.Text.Json.Utf8JsonReader&amp; reader, System.Text.Json.ReadStack&amp; state) &lt;0x30a3b58 + 0x00100&gt; in &lt;filename unknown&gt;:0 
    at System.Text.Json.JsonSerializer.ReadCore (System.Text.Json.JsonSerializerOptions options, System.Text.Json.Utf8JsonReader&amp; reader, System.Text.Json.ReadStack&amp; readStack) &lt;0x30a3218 + 0x0026a&gt; in &lt;filename unknown&gt;:0 
     --- End of inner exception stack trace ---
    at System.Text.Json.ThrowHelper.ReThrowWithPath (System.Text.Json.ReadStack&amp; readStack, System.Text.Json.Utf8JsonReader&amp; reader, System.Exception ex) &lt;0x30e4740 + 0x00028&gt; in &lt;filename unknown&gt;:0 
    at System.Text.Json.JsonSerializer.ReadCore (System.Text.Json.JsonSerializerOptions options, System.Text.Json.Utf8JsonReader&amp; reader, System.Text.Json.ReadStack&amp; readStack) &lt;0x30a3218 + 0x00320&gt; in &lt;filename unknown&gt;:0 
    at System.Text.Json.JsonSerializer.ReadValueCore (System.Text.Json.JsonSerializerOptions options, System.Text.Json.Utf8JsonReader&amp; reader, System.Text.Json.ReadStack&amp; readStack) &lt;0x309fe18 + 0x00592&gt; in &lt;filename unknown&gt;:0 
    at System.Text.Json.JsonSerializer.ReadValueCore (System.Text.Json.Utf8JsonReader&amp; reader, System.Type returnType, System.Text.Json.JsonSerializerOptions options) &lt;0x309e998 + 0x0003e&gt; in &lt;filename unknown&gt;:0 
    at System.Text.Json.JsonSerializer.Deserialize (System.Text.Json.Utf8JsonReader&amp; reader, System.Type returnType, System.Text.Json.JsonSerializerOptions options) &lt;0x309e830 + 0x00024&gt; in &lt;filename unknown&gt;:0 
    at Microsoft.JSInterop.JSRuntime.EndInvokeJS (System.Int64 taskId, System.Boolean succeeded, System.Text.Json.Utf8JsonReader&amp; jsonReader) &lt;0x2c8a120 + 0x00052&gt; in &lt;filename unknown&gt;:0 
     --- End of inner exception stack trace ---
    at System.Threading.Tasks.ValueTask`1[TResult].get_Result () &lt;0x30f2538 + 0x00034&gt; in &lt;filename unknown&gt;:0 
    at TestApp.Client.KeyboardManagerTest.Initialize () [0x0003d] in &lt;Path&gt;\Client\Test.cs:27 
    at TestApp.Client.Pages.TestPage.OnInitializedAsync () [0x00109] in &lt;Path&gt;\Client\Pages\TestPage.razor:49 
    at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync () &lt;0x2ddec48 + 0x0013a&gt; in &lt;filename unknown&gt;:0 
    at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask (System.Threading.Tasks.Task taskToHandle) &lt;0x2f2fa10 + 0x000b6&gt; in &lt;filename unknown&gt;:0
  </code></pre>
  <p><strong>Direct JS call within the Browser's debug tools</strong></p>
  <pre class="lang-js prettyprint-override"><code>UtilityTest.testFunc()
  true
  </code></pre>
  <p><code>&lt;Path&gt;\Client\Test.cs:27</code> refers to the <code>JsRuntime.InvokeAsync</code> line. I really don't know why the exception is thrown (<code>JsRuntime.InvokeVoidAsync</code> works). I hope someone can help me with this.</p>