Recursive Response Type Breaks Type Generation

I added a recursive response type the other day for a tree view type of service. Something simple like

class Node : IHasGuidId {
    public Guid Id {get;set;}
    public string Text {get;set;}
    public Node[] Children {get;set;}
}

And found out that type generation for typescript (and presumably others) broke. SS fell into an infinite loop here: https://github.com/ServiceStack/ServiceStack/blob/1036956603d1288ec908aca6f8720a2c352b2a73/src/ServiceStack/NativeTypes/NativeTypesMetadata.cs#L187

The property type info just keeps getting added to the queue over and over on line #173

Something simple like

if (!considered.Contains(t))
{
     considered.Add(t);
     queue.Enqueue(t);
 }

Would fix it from what I see but I’m no expert here

Yeah that should resolve the issue from this commit, this change is now available from the latest v5.4.1 that’s now on MyGet.

Note I’d recommend against recursive types in service contracts which will fail to serialize in many serializers and will likely run into issues from consuming in different languages. For sending a tree structure I’d just return a flat list with a “ParentId” and just have the client build a dictionary indexed by parent id to create the tree structure on the client.