Deleting Media Assets Episerver Commerce

How to delete and update commerce media assets properly.

Warning: A non-numeric value encountered in /storage/content/29/141529/ on line 27

Published 30 dec 2020
Episerver Commerce 10 to 13

“Media not found”

This happens when the image is deleted from the CMS media but still linked in the Commerce Media Asset Pane UI.

Why? because it is possible to delete the image with code, without getting the warning like you get from the UI.

Still you can “move to trash” and empty trash bin, then you get “Media not found” in commerce media assets.

Error: “Navigate to Assets tab and remove it in order to publish”

“System.ComponentModel.DataAnnotations.ValidationException: Media is not found. Navigate to Assets tab and remove it in order to publish.” – you get this error if you try to publish the catalog item, when item has an linked asset that is deleted from media pane. The message explains how to solve it manually in the UI.

How to avoid the error – unlink media

The trick is to unlink the media asset before you delete it.

If you are working from code, you may find the use of the media with GetReferencesToContent on IContenRepository

Example GetReferencesToContent:

Example UnLinkCommerceMedia method:

Example how to remove “media not found” on commerce media collection

Example “Attach media to commerce items”:

Related links

About the author

Luc Gosso
– Independent Senior Web Developer
working with Azure and Episerver

Twitter: @LucGosso

Like it? please up vote

Leave a Reply

Your email address will not be published. Required fields are marked *