The Select Media dialog shows wrong or broken preview thumbnail for versioned media items


Description

Broken preview thumbnails might be shown when browsing for a media item using the Select Media dialog. For example:

 

 

The issue occurs for versioned media items that do not have a version in the default language. The issue affects both the List View and the Tree View. The following message can be found in the Sitecore logs:

ERROR Application error.
Exception: System.ObjectDisposedException
Message: Cannot access a closed file.
Source: mscorlib
   at System.IO.__Error.FileNotOpen()
   at System.IO.FileStream.get_Length()
   at Sitecore.Resources.Media.Streaming.RangeRetrievalResponse.WriteFullContent(HttpContext context, Stream fileContent)
   at Sitecore.Resources.Media.MediaRequestHandler.DoProcessRequest(HttpContext context, MediaRequest request, Media media)
   at Sitecore.Resources.Media.MediaRequestHandler.ProcessRequest(HttpContext context)

Solution

To resolve the issue, upgrade your solution to Sitecore XP 10.4.0 or later.

To mitigate the issue:

  1. Open the file:
    <site_root>\sitecore\shell\client\Business Component Library\Layouts\Renderings\ListsAndGrids\TreeViews\ItemTreeView.js
  2.  Find the "appendLanguageParameter" function.
  3. Change:
    if (item.$icon && item.$icon.indexOf(".ashx") > 0 && item.$icon.indexOf("la=") === -1 ) {
      item.$icon += "&la=" + this.model.get("contentLanguage");
    }
    if (item.$mediaurl && item.$mediaurl.indexOf(".ashx") > 0 && item.$mediaurl.indexOf("la=") === -1 ) {
      item.$mediaurl += "&la=" + this.model.get("contentLanguage");
    }
    to:
    /* Fix for 539825 */
    if (item.$icon && item.$icon.indexOf("la=") === -1 ) {
      item.$icon += "&la=" + this.model.get("contentLanguage");
    }
    if (item.$mediaurl && item.$mediaurl.indexOf("la=") === -1 ) {
      item.$mediaurl += "&la=" + this.model.get("contentLanguage");
    }
    /* End of fix for 539825 */
  4. Repeat steps 2 and 3 for the following file:
    <site_root>\sitecore\shell\client\Business Component Library\Layouts\Renderings\ListsAndGrids\ListControls\ListControl.js
  5. Clear the browser cache and verify that the suggested solution works.