Problem with dependency injection (File::load and \Drupal::service)
If you are extending FormBase you can use create to inject dependencies. In this case what I think you want is the entity_type.manager service and file.usage.

  /**
   * Class constructor.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager, FileUsageInterface $file_usage) {
    $this-&gt;entityTypeManager = $entity_type_manager;
    $this-&gt;fileUsage = $file_usage;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static(
      $container-&gt;get('entity_type.manager'),
      $container-&gt;get('file.usage')
    );
  }


See this docs page for more examples.

The create method sends arguments to the constructor, and then you set those to instance variables, and voila, there are your dependencies. Be sure to update your file with the necessary use statements and declare your protected members (entityTypeManager and fileUsage) at the top of the form class.

Therefore, you can remove the static ::service call and use:

$this-&gt;fileUsage-&gt;add()...

Also, the reason I am passing entity type manager service, is because you would replace File::load with:

$this-&gt;entityTypeManager-&gt;getStorage('file')-&gt;load($id);

If you need more than that object returns, you may need to use a different service but I don't know that off the top of my head.