title: Blazor - Send Message problem using SignalR
body: <p>I have created fairly complicated Blazor apps, calling web APIs, injecting services and using 3rd party libraries. But I am using SignalR first time ever. My setup is:</p>
  <ul>
  <li>ASP.NET Core Web API (do the heavy lifting)</li>
  <li>Front end - Blazor App (server side - calling web api via Services classes i created in blazor project)</li>
  </ul>
  <p>Everything is working fine. I have created a hub in my api and expose the endpoint. Through blazer clients, i can establish the connection and connecting extra clients are notified to all clients via hub.</p>
  <p><a href="https://i.stack.imgur.com/VaFdx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VaFdx.png" alt="enter image description here" /></a></p>
  <p><strong>THE PROBLEM</strong>
  I am getting a very bizarre message when trying to send/broadcast a message from client to server/hub. When clicking the Send button, I am getting 'Uncaught SyntaxError: Unexpected number'</p>
  <p><a href="https://i.stack.imgur.com/BWE7T.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BWE7T.png" alt="enter image description here" /></a></p>
  <p>Clicking on the link on the error, it gives me;</p>
  <p>System.Runtime.CompilerServices.AsyncTaskMethodBuilder<code>1+AsyncStateMachineBox</code>1[System.Threading.Tasks.VoidTaskResult,MBOSS.Pages.Index+d__6]</p>
  <p><strong>CODE</strong></p>
  <p>My 'Index.razror' component is very simple (as follows):</p>
  <pre><code>@page &quot;/index&quot;
  @using Microsoft.AspNetCore.SignalR.Client
  
  &lt;div class=&quot;container&quot;&gt;
      &lt;input type=&quot;text&quot; id=&quot;message&quot; class=&quot;form-control&quot; bind=&quot;@Message&quot; /&gt;
      &lt;input type=&quot;button&quot; id=&quot;sendMessage&quot; value=&quot;Send&quot; class=&quot;btn btn-primary&quot; onclick=&quot;@SendMessage()&quot; /&gt;
      &lt;ul id=&quot;discussion&quot;&gt;
          @foreach (var message in messages)
          {
              &lt;li&gt;@message&lt;/li&gt;
          }
      &lt;/ul&gt;
  &lt;/div&gt;
  
  @code{
          HubConnection connection;
          string Message = &quot;&quot;;
          IList&lt;string&gt; messages = new List&lt;string&gt;();
  
      protected override async Task OnInitializedAsync()
      {
          connection = new HubConnectionBuilder().WithUrl(&quot;http://localhost:63572/livedata&quot;).Build();
          connection.On&lt;string, string&gt;(&quot;broadcastMessage&quot;, this.OnBroadcastMessage);
          await connection.StartAsync();
      }
  
      Task OnBroadcastMessage(string name, string message)
      {
          if (!string.IsNullOrEmpty(message))
          {
              messages.Add(name + &quot; : &quot; + message);
              StateHasChanged();
          }
          return Task.CompletedTask;
      }
  
      async Task SendMessage()
      {
          await connection.InvokeAsync(&quot;Send&quot;, &quot;Blazor Client&quot;, Message);
          Message = &quot;&quot;;
      }
  }
  </code></pre>
  <p>My hub class is very simple as well;</p>
  <pre><code>using Microsoft.AspNetCore.SignalR;
  using System.Threading.Tasks;
  
  namespace SignalRTest
  {
      public class LiveData : Hub
      {
          public override Task OnConnectedAsync()
          {
              Clients.All.SendAsync(&quot;broadcastMessage&quot;, &quot;system&quot;, $&quot;{Context.ConnectionId} joined the conversation&quot;);
              return base.OnConnectedAsync();
          }
          public void Send(string name, string message)
          {
              Clients.All.SendAsync(&quot;broadcastMessage&quot;, name, message);
          }
  
          public override Task OnDisconnectedAsync(System.Exception exception)
          {
              Clients.All.SendAsync(&quot;broadcastMessage&quot;, &quot;system&quot;, $&quot;{Context.ConnectionId} left the conversation&quot;);
              return base.OnDisconnectedAsync(exception);
          }
      }
  }
  </code></pre>
  <p>Can someone please suggest, how to solve the problem so I can start using SignalR with Blazor.</p>
  <p>Many thanks</p>