title: SignalR angular gets disconnected while getting a dictionary object
body: <p>Using asp.net core 2.2 and angular 7, (asp.netcore:signalr 1.1.0 + angular:"@aspnet/signalr": "^1.1.4")</p>
  
  <p>it was working fine until i tried to send a dictionary to angular. when it tries to send the dictionary it gets disconnected.</p>
  
  <pre><code>Utils.js:209 [2019-12-29T11:09:11.959Z] Information: WebSocket connected to ws://localhost:64408/chat?id=6d-C7eu1X-Pv8t4-RwdbYg. 
  Utils.js:209 [2019-12-29T11:09:12.132Z] Information: Connection disconnected.
  </code></pre>
  
  <p>These are my codes:</p>
  
  <p>InMemoryChatRoomService class:</p>
  
  <pre><code> public class InMemoryChatRoomService : IChatRoomService
      {
          private readonly Dictionary&lt;Guid, ChatRoom&gt; _roomInfo = new Dictionary&lt;Guid, ChatRoom&gt;();
  
          public Task&lt;IReadOnlyDictionary&lt;Guid, ChatRoom&gt;&gt; GetAllRooms()
          { 
              return Task.FromResult(_roomInfo as IReadOnlyDictionary&lt;Guid, ChatRoom&gt;);
          } 
  
      }
  </code></pre>
  
  <p>IChatroomService:</p>
  
  <pre><code>using SignalR.Models;
  using System;
  using System.Collections.Generic;
  using System.Threading.Tasks;
  
  namespace SignalR
  {
      public interface IChatRoomService
      {
  
          Task&lt;IReadOnlyDictionary&lt;Guid, ChatRoom&gt;&gt; GetAllRooms(); 
      }
  }
  </code></pre>
  
  <p>ChatHub class:</p>
  
  <pre><code>using Microsoft.AspNetCore.SignalR;
  using SignalR.Models;
  using System;
  using System.Collections.Generic;
  using System.Threading.Tasks;
  
  namespace SignalR
  {
      public class ChatHub : Hub
      {
          private readonly IChatRoomService _chatRoomService;
          public ChatHub(IChatRoomService ChatRoomService)
          {
              _chatRoomService = ChatRoomService;
  
          }
          public override async Task OnConnectedAsync()
          { 
              await Clients.Caller.SendAsync("ActiveRooms", await _chatRoomService.GetAllRooms()); 
              await base.OnConnectedAsync();
          }
      }
  }
  </code></pre>
  
  <p>angular:</p>
  
  <pre><code>import { Component, OnInit } from '@angular/core';
  import * as signalR from "@aspnet/signalr";
  import { HttpClient } from "@angular/common/http";
  import { MessagePacket } from './MessagePacket.model';
  import { ChatService } from './chat.service';
  import { ChatRoom } from './ChatRoom.model';
  
  @Component({
      selector: 'app-chat',
      templateUrl: './chat.component.html',
      styleUrls: ['./chat.component.scss']
  })
  export class ChatComponent implements OnInit {
  
      constructor(private http: HttpClient, private chatService: ChatService) { }
  
      private hub: signalR.HubConnection;
      rooms = [ ];
      messagePackets: MessagePacket[] = [];
      isConnected = false;
      connectionAttempts = 0;
      ipAddress = '';
      typedMessage = '';
      userChatName = 'salar';//todo: load user data
  
      ngOnInit() { 
          //build connection
          this.hub = new signalR.HubConnectionBuilder()
              .withUrl('http://localhost:64408/chat')
              .build();
  
          //start connection
          this.startConnection();
  
  
          this.hub.on('ActiveRooms', (rooms ) =&gt; {
              this.ActiveRooms(rooms)
          });
  
  
          //on disconnect
          this.hub.onclose(h =&gt; {
              this.isConnected = false;
               setTimeout(x =&gt; this.startConnection(), 3000)
          });
      }
  
      startConnection() {
          this.connectionAttempts++;
          console.log('Connecting!')
          this.hub
              .start()
              .then(() =&gt; {
                  this.connectionAttempts = 0;
                  this.isConnected = true;
                  console.log('Connection started!');
                  console.log('Getting all rooms');
                 // this.hub.invoke("ActiveRooms");
  
              })
              .catch(err =&gt; {
                  if (this.connectionAttempts &lt; 10) {
                      console.log(this.connectionAttempts + ' try for connection')
                       setTimeout(x =&gt; this.startConnection(), 3000)
                  } else {
                      console.log('Error while establishing connection. changed mode to manual')
                  }
              });
      }
  
  
      ActiveRooms(rooms ) {
          var x = '';
         // this.rooms = rooms;
      }
  
  
  }
  </code></pre>
  
  <p>when i trace, it tries to send back the dictionary, and after that , signalr gets disconnected and tries to connect again. if it not be dictionary and be like a string or another object, it is working fine.</p>
  
  <p><strong><em>UPDATE:</em></strong></p>
  
  <p>when i change the type GUID of dictionary to STRING it gets alright:</p>
  
  <pre><code> public Task&lt;IReadOnlyDictionary&lt;string, ChatRoom&gt;&gt; GetAllRooms()
          {
              //type guid gives error so needs to be converted to string
              Dictionary&lt;string, ChatRoom&gt; result = new Dictionary&lt;string, ChatRoom&gt;();
              foreach (var room in _roomInfo)
              {
                  result.Add(room.Key.ToString(), room.Value);
              }
              return Task.FromResult(result as IReadOnlyDictionary&lt;string, ChatRoom&gt;);
          } 
  </code></pre>
  
  <p>It has some problem with GUID.</p>