What is your complete code? You should create a write-able clone of the content, then remove the asset, and save it
var clone = catalogContent.CreateWritableClone<CatalogContentBase>();
var commerceMediaCollection = ((IAssetContainer) clone).CommerceMediaCollection;
var commerceMedia = commerceMediaCollection.FirstOrDefault(x => x.AssetLink == mediaReference);
commerceMediaCollection.Remove(commerceMedia); // returns true
_contentRepository.Save(clone, SaveAction.Publish | SaveAction.ForceCurrentVersion, AccessLevel.NoAccess);
That looks correct. Which version are you using? Does the asset disappear if you restart the site and/or clear the browser cache?
I'm using Episerver Commerce v12.0.0 with Episerver CMS v11.12.0. The asset does not disappear when I restart the site nor when I clear the browser cache. It has worked previously too, I might add.
What do you mean " has worked previously"? did it work on same version, of it worked on an older version and stopped working once you upgraded?
It has worked on the exact same code, same versions on the CMS and Commerce. That's why I can't figure out what's causing this.
Using ((IAssetContainer) clone).CommerceMediaCollection.Remove(commerceMedia); I expect the asset to be removed from the commerce media collection. The method returns true, but the asset is still visible in the catalog. What could be the cause of this? (Even ((IAssetContainer) clone).CommerceMediaCollection.Clear(); doesn't empty the commerce media collection.)