private InvokeResult GetInvokationResult(InvokeMessage message) { object data; try { data = invoker.Invoke(message, CreateRemoteInvoker); } catch (Exception ex) { return(InvokeResult.Exception(message.Id, ex)); } if (data == null) { return(InvokeResult.Null(message.Id)); } if (data is Stream stream) { return(InvokeResult.Stream(message.Id, stream)); } if (PrimitiveTypes.Contains(data.GetType())) { return(InvokeResult.Primitive(message.Id, JToken.FromObject(data))); } var codeInvoker = new CodeInvoker(data, data.GetType()); long newId; //TODO lock need? lock (subWrappers) { newId = ++lastId; subWrappers[newId] = new InstanceWrapper(codeInvoker); } return(InvokeResult.HardObject(message.Id, newId)); }