Viewing an image file breaks if view mode has responsive image style I have an image file that I am viewing programmatically. When I set the image format to "responsive image" in file display settings, it breaks with an error 

Error: Call to a member function getMetadata() on null in file_entity_preprocess_responsive_image_formatter() (line 488 of modules/contrib/file_entity/file_entity.module).


My render code:

$file = File::load($fid);
$build = [];
if ($file) {
  $view_builder = \Drupal::entityTypeManager()-&gt;getViewBuilder($file-&gt;getEntityTypeId());
  $build = $view_builder-&gt;view($file, 'embed');
}


"embed" is the file view mode that sets the image to display as responsive.

There seems to be missing the "item" in the build array resulting from this, which is expected to be a fielditem. Am I doing something wrong?
This is not a proper answer, but a workaround in case someone else has this issue: detect if a responsive style is used, load it, and apply via theme layer (the style name is hard-coded to be "embed"):

if ($file) {
  $view_mode = \Drupal::entityTypeManager()
     -&gt;getStorage('entity_view_display')
     -&gt;load('file.' . $file-&gt;bundle() . '.embed');
  $content = $view_mode-&gt;get('content');

  // Responsive.
  if (!empty($content['uri']['settings']['responsive_image_style'])) {
    $build = [
      '#theme' =&gt; 'responsive_image',
      '#responsive_image_style_id' =&gt; $content['uri']['settings']['responsive_image_style'],
      '#uri' =&gt; $file-&gt;getFileUri(),
    ];
  }

  // Non responsive.
  else {
    $view_builder = \Drupal::entityTypeManager()-&gt;getViewBuilder($file-&gt;getEntityTypeId());
    $build = $view_builder-&gt;view($file, 'embed');
  }
}