title: Blazor - JavaScript Interop - No .NET call dispatcher has been set
body: <p>I am experimenting with a <a href="https://docs.microsoft.com/en-us/aspnet/core/blazor/hosting-models?view=aspnetcore-3.1#blazor-webassembly" rel="nofollow noreferrer">Blazor WebAssembly app</a>. When my page (i.e. index.html) loads, I want to pass a JavaScript array to the Blazor app when it loads. While trying to <a href="https://docs.microsoft.com/en-us/aspnet/core/blazor/call-dotnet-from-javascript?view=aspnetcore-3.1" rel="nofollow noreferrer">call a method from JavaScript</a>, I've run into an error that says:</p>
  <pre><code>Uncaught (in promise) Error: No .NET call dispatcher has been set
  </code></pre>
  <p>My code looks like this:</p>
  <p><strong>index.html</strong></p>
  <pre><code>&lt;body&gt;
      &lt;app&gt;Loading...&lt;/app&gt;
  
      &lt;div id=&quot;blazor-error-ui&quot;&gt;
          An unhandled error has occurred.
          &lt;a href=&quot;&quot; class=&quot;reload&quot;&gt;Reload&lt;/a&gt;
          &lt;a class=&quot;dismiss&quot;&gt;&lt;/a&gt;
      &lt;/div&gt;
      &lt;script src=&quot;_framework/blazor.webassembly.js&quot;&gt;&lt;/script&gt;
  
      &lt;script&gt;
          let items = [
              { name:'Item 1', description:'This is a description of the first item' },
              { name:'Item 2', description:'This is a description of the second item' },
              { name:'Item 3', description:'This is a description of the third item' },
          ];
  
          try
          {
              DotNet
                  .invokeMethodAsync('MyOrg.MyApp.Index', 'LoadItems')
                  .then(results =&gt; {
                      console.log(results);
                  })
              ;
          }
          catch (ex)
          {
              console.log(ex);
          }
      &lt;/script&gt;
  &lt;/body&gt;
  </code></pre>
  <p><strong>Index.razor</strong></p>
  <pre><code>@page &quot;/&quot;
  
  @using System.Threading.Tasks;    
  @using Microsoft.Extensions.Logging;
  
  @inject ILogger&lt;Index&gt; logger;
  
  &lt;p&gt;
      Items loaded: &lt;span&gt;@items.Count&lt;/span&gt;
  &lt;/p&gt;
  
  @code {
      List&lt;object&gt; items = new List&lt;object&gt;();
  
      [JSInvokable]
      private Task LoadSnippets() 
      {
          try 
          {
              logger.LogInformation(&quot;Loading items...&quot;);
              items = new List&lt;object&gt;();
          }
          catch (Exception ex)
          {
              logger.LogError(ex, $&quot;Failed to load items.&quot;);
          }
          return Task.CompletedTask;
      }
  }
  </code></pre>
  <p>The first difference I noticed was that the example shown in the docs relied on a <code>static</code> method. Is this a requirement? If so, that would imply there's not a way to perform logging for example. Logging aside, even if I add <code>static</code> to the <code>LoadItems</code> method, I still get the error listed above. I don't understand why.</p>
  <p>In short, I'm trying to create a &quot;headless&quot; Blazor app. I'd like to use the richness of C# to work with the data, I need to pass the results to the UI, which relies on HTML/CSS. Thank you!</p>