Try our conversational search powered by Generative AI!

"CommerceMediaNotFound" Exception thrown when trying to publish variant using ContentRepository

Vote:
 

We're using a webapi to add available deliverymethods and price to a variant from an external system.
The variant is retrieved, created as a writeable cone, updated with new data, then saved. But the save sometimes crashes, with the following message:

System.ComponentModel.DataAnnotations.ValidationException: [Missing text '/Commerce/validation/commercemedianotfound' for 'English']

When i debug the code, the CommerceMediaCollection contains more images than what is visible on the product in the admin-interface. As if the entry has "invisible" images linked.

The problem seems to originate from InRiver (OnPremise version). The error only occurs when the customer creates a new product in inriver, a new variant in inriver and connects a new image in inriver. Not when connecting an already existing image, for example.

I have verified that the image is imported to episerver, i can see it in the media catalog. The variant also gets the correct image as an asset.

this is the line that crashes, giving the above error message.

ContentRepository.Save(variant, SaveAction.Publish.SetExtendedActionFlag(ExtendedSaveAction.ClearVersions), AccessLevel.NoAccess);

I tried adding a new image to the variant in the edit-interface, publishing it, then removing the new image and publishing again. After a recycle of the appPool, that seems to have solved the issue for that particular variant. But given that the issue happens for every newly created variant with a new asset, and that it has already happened for well over 1000 variants, that seems like an unsustainable solution.

Has anyone seen something like this before?

CMS-version 11.12
Commerce-version 12.11
InRiver PIM 6.3 SP3. (on premise version)


#219014
Mar 27, 2020 7:58
Vote:
 

You can probably try to do this before saving your entry

var notExistMedia = entry.CommerceMediaCollection.Where(m => ContentReference.IsNullOrEmpty(media.AssetLink)).ToList();

foreach (var media in notExistMedia )
{
entry.CommerceMediaCollection.Remove(media);

}

#219017
Mar 27, 2020 8:32
Vote:
 

I will give it a try

#219018
Mar 27, 2020 8:41
Vote:
 

Tried this out, this removed all assetlinks from the variant. Even the "correct" ones. It seems assetlink is null or empty for all images on variants for us. Even images that exists
and is working fine. 

#219120
Mar 30, 2020 6:49
Vote:
 

Did you look into notExistMedia? How can a media with empty AssetLink "exists and is working fine"?

#219121
Mar 30, 2020 6:51
Vote:
 

Yes, i implemented your suggestion. And i honestly don't know why the image is working desipite assetlink being null. 

Here is the image on the variant:




Here is the media file in the media catalog (so the image does exist in epi) : 



And this is after the code updating the variant (with the notExistMedia code-snippet added):


#219134
Mar 30, 2020 7:29
Vote:
 

No I meant looking into the variable during debugging. 

#219141
Mar 30, 2020 7:57
Vote:
 

Now i can't recreate the same behaviour in my development environment for some reason, so i can't show you the model when debugging. The issue still remains on the production environment though. And after implementing the code-snippet above, a lot of articles lost their fully functional asset link. I will try to reproduce the same bug locally to show you how the variable looks.

#219210
Mar 31, 2020 9:17
Vote:
 

In your screenshot above it looks like Drake-a5.jpg does not really exist. it should have a thumbnail if it does.

Do you have a custom asset provider? 

#219212
Mar 31, 2020 9:28
Vote:
 

Hm, even though the image doesn't have a thumbnail i can still see the image if i navigate to that variants productpage. 
There the image url is retrieved by something like this:

return variant.CommerceMediaCollection.Select(media => _urlResolver.Service.GetUrl(media.AssetLink))
.FirstOrDefault();

Which is weird, given that the image is removed by the snippet you sent earlier. 

The image does seem to exist, perhaps it's only the thumbnail/preview that doesn't exist. Because if i go to the image url at /globalassets/importedresources/d/inrivergenericmedia/drake-a5.jpg,

the image is shown as well. 

Somehow the variant is retrieved with faulty CommerceMediaCollection (where assetlink seems to be null for some reason).
Can the variants assets be cached with broken assetlinks somehow?


#219215
Mar 31, 2020 11:07
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.