public static async Task WriteObject(IRequest request, object result, IResponse response) { var contentType = request.ResponseContentType; var serializer = ContentTypes.GetStreamSerializer(contentType); using (var ms = new MemoryStream()) { serializer(result, ms); ms.Position = 0; response.SetContentLength(ms.Length); await ms.CopyToAsync(response.OutputStream).ConfigureAwait(false); } //serializer(result, outputStream); }