undefined method Drupal core URL render in template method toString must not throw an exception

This change was needed because ‘url()’ method was removed from FormBase:

-    $form['#action'] = $this->url('findit_search.search');
+    $form['#action'] = \Drupal\Core\Url::fromRoute('findit_search.search');

But it resulted in a harder-to-track-down error:

“Call to undefined method Drupal\Core\Url::render()”

buried in an indeterminate (but also innocent) Twig template.

That was wrapped in all this mess:

[09-Sep-2021 15:00:42] WARNING: [pool www] child 75759 said into stderr: "NOTICE: PHP message: PHP Fatal error:  Method Drupal\Core\Template\Attribute::__toString() must not throw an exception, caught Error: Call to undefined method Drupal\Core\Url::render() in /var/www/html/web/sites/default/files/php/twig/613a21993788b_form.html.twig_6hDWqscLwUGaxSubSPoJrz7dW/mNrw1lAHhvDnhrzKpa6WYY3_lP85xVJQ_fN25dl5w3c.php on line 0"
[Thu Sep 09 15:00:42.220444 2021] [proxy_fcgi:error] [pid 2049] [client 172.18.0.7:57264] AH01071: Got error 'PHP message: PHP Fatal error:  Method Drupal\\Core\\Template\\Attribute::__toString() must not throw an exception, caught Error: Call to undefined method Drupal\\Core\\Url::render() in /var/www/html/web/sites/default/files/php/twig/613a21993788b_form.html.twig_6hDWqscLwUGaxSubSPoJrz7dW/mNrw1lAHhvDnhrzKpa6WYY3_lP85xVJQ_fN25dl5w3c.php on line 0', referer: https://findit-dev.ddev.site/admin/content

Anyway the fix was what you’d expect, giving it a string so it couldn’t trip up trying to produce a string:

    $url = \Drupal\Core\Url::fromRoute('findit_search.search');
    $form['#action'] = $url->toString();
    $form['#method'] = 'get';

Though it felt like i needed more than one cache reload to get it to stop producing unexpected “PHP message: Error: Using $this when not in object context in /var/www/html/web/core/lib/Drupal/Core/Url.php on line 759” which may have come from me momentarily using ::toString() instead of ->toString().