'File used may not be referenced' if form field submits same image twice
Using the skumy's approach worked for me, but instead of putting 'managed_file' as the third parameter for $file_usage->add(), I put 'file'.

$fid = $config['image'][0];
$file = File::load($fid);
$file-&gt;status = FILE_STATUS_PERMANENT;  
$file-&gt;save();
$file_usage = \Drupal::service('file.usage');
$file_usage-&gt;add($file, 'mymodule', 'file', $fid);


That's because putting 'managed_file' causes an error when I check the file usages, following the links in the "Used in" column in /admin/content/files, since in my installation does not exist any entity called 'managed_file'.


  The "managed_file" entity type does not exist




Using 'file' instead of 'managed_file' solves the problem.