I am developing a chatting system on ASP.NET MVC using SignalR, I send to the front through the Clients.Caller.onConnected method a lot of messages and comments.

public override Task OnConnected() { var currentUser = HttpContext.Current.GetOwinContext().GetUserManager<ApplicationUserManager>().FindById(HttpContext.Current.User.Identity.GetUserId()); string id = Context.ConnectionId; string name = currentUser.ChatName; var messages = (from user in context.Users join message in context.Messages on user.Id equals message.UserId select new { user.ChatName, user.Photo, message.MessageText, message.Id}).ToList(); var comments = (from coment in context.Comments join user in context.Users on coment.UserId equals user.Id select new { user.ChatName, user.Photo, coment.CommentText, coment.Id, coment.MessageId }).ToList(); if (Users.Values.All(x => x != name)) { Users.Add(Context.ConnectionId, name); Clients.Caller.onConnected(id, name, Users, messages, comments);// Вот здесь вылазит exception Clients.AllExcept(id).onNewUserConnected(id, name); } return base.OnConnected(); } 

The first page load is normal. After rebooting from the onConnected method, I get an error - An exception of type 'System.OutOfMemoryException' occurred in the newtonsoft.Json.dll. Maybe someone came across, can somehow optimize json?

enter image description here

  • how much is given and how is it sent? if you reduce the size of the data error goes away? - Grundy
  • Yes, if there are not many messages and comments until about 20 ti - Nick Synev
  • What do the sent objects look like? - Grundy
  • Attached to the question, comments on the same pattern - Nick Synev
  • Ooooooooooooooooooooooooooooo, I see the photo. try to remove this field when sending - Grundy

0