0

It seems like a Microsoft bug. If I try to return an object from a function in the server called by a client and the object has a circular reference to its own:

public class User
{
   public User OtherUser;
}

public User GetUser()
{
  User user = new User();
  user.OtherUser = new User();
  user.OtherUser.OtherUser = user;
  return user.OtherUser;
}

The server function is recalled again and then the hub doesn't respond to further calls, anyone encountered this behavior? I turned into using an id of the object instead of a reference to the object to solve this.

Ronen Festinger
  • 2,260
  • 1
  • 23
  • 32
  • Welcome to StackOverflow! Please see ["Should questions include “tags” in their titles?"](http://meta.stackexchange.com/questions/19190/should-questions-include-tags-in-their-titles), where the consensus is "no, they should not". –  Dec 02 '14 at 15:27

2 Answers2

1

You might consider an alternate model, employing both SignalR and Web API. SignalR is for pushing data to the client, right? What if the client is no longer there? In that case, it does not make sense to push a large object from the server out into the void where it will not be picked up.

An alternate approach is to use SignalR to push small pieces of information - e.g. a User ID - and then have the browser call back to a service (hence Web API) to get the larger payload when ready for it.

sfuqua
  • 5,797
  • 1
  • 32
  • 33
  • Good idea, but I prefer here simplicity. If the user will be disconnected there is an event that removes him from the connected user list and it will be null and nothing will happen. – Ronen Festinger Dec 02 '14 at 16:23
0

I think it's related to this problem of circular reference and Json.

A circular reference was detected while serializing an object of type 'SubSonic.Schema .DatabaseColumn'.

Community
  • 1
  • 1
Ronen Festinger
  • 2,260
  • 1
  • 23
  • 32