I have this error in Drupal 8.9.20 in a custom module: "Error: Call to a member function __toString()" with this code:
$html = \Drupal::service('renderer')
->renderRoot($template)
->__toString();
$result = new Response($html, 200);
Until the update to Drupal 8.9, it worked.
With what should i replace "__toString()" ?
I tried to replace with getContent() but with no succes.