'File' class not found in submitForm(...) - uploading managed_file I have an image field in my custom module's form:

namespace Drupal\my_module\Form;

use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;

use Drupal\Core\Mail\MailManagerInterface;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Component\Utility\Html;

class MyModuleForm extends FormBase {

  public function buildForm(array $form, FormStateInterface $form_state) {
    $form['image_file'] = array(
      '#type' =&gt; 'managed_file',
      '#name' =&gt; 'image_file',
      '#title' =&gt; t('Block image'),
      '#size' =&gt; 40,
      '#description' =&gt; t("Image should be less than 400 pixels wide and in JPG format."),
      '#upload_location' =&gt; 'public://myimages/'
    ); 
...


And for submitForm(...) I use:

  public function submitForm(array &amp;$form, FormStateInterface $form_state){
    $image = $form_state-&gt;getValue('image_file');
    $file = File::load( $image[0] );
    $file-&gt;setPermanent();
    $file-&gt;save();
    ...


But when I use the form to submit image I get error (in log):


  Error: Class 'Drupal\my_module\Form\File' not found in ...
You need to add it in a use statement in your class (at the top of the file with the rest of the use statements)

use Drupal\file\Entity\File;