Try our conversational search powered by Generative AI!

Exception: Cannot use System.DBNull as System.String (VariationContent)

Vote:
 

Hi,

We are developing a online store where we are trying to upload product images in the CMS that should be connected to products.

In the screenshot below we are trying to do the connecting-part.

'imageRef' is the ContentReference to the already uploaded image (uploaded to global assets in the CMS)

'variationContent' contains information about the product that we want to connect 'imageRef' to. 

'variationContent.CommerceMediaContent' is the imagelist for the product where we are trying to add the image.

However, when we are trying to save this using the contentrepository it gives us an exception saying that we cannot use System.DBNull as System.String.

(In the biggest if statement we are trying to remove existing images that we want to replace. We can comment this code out and still get the same exception.)

It doesn't seem like anything is being saved in the database. Any ideas?

Versions we are using: EPiServer CMS 9.12 + Commerce 9.24

#217675
Edited, Feb 27, 2020 10:38
Vote:
 

That is an really old version...

Can you show the entire stacktrace?

One thing that leaps to mind, that you can try, is to set a GroupName and/or AssetType for that new CommerceMedia:

var commerceMedia = new CommerceMedia { 
AssetLink = imageRef, 
GroupName = "image",
AssetType = sg.core.Constants.Pim.ImageUpload.ImageTypes.MainImageTypeString.ToLower()
 };
#217693
Feb 27, 2020 15:22
Vote:
 

Thanks, that solved our problem!

#217862
Mar 02, 2020 13:18
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.