# productModel.GetValue() throws on some products

**URL:** <https://forum.litium.com/t/productmodel-getvalue-throws-on-some-products/579>\
**Category:** Questions\
**Created:** [February 11, 2019, 9:24am UTC](https://forum.litium.com/t/productmodel-getvalue-throws-on-some-products/579 "2019-02-11T09:24:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robin.w](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/robin.w/32/75_2.png) [@Robin.w](https://forum.litium.com/u/Robin.w)\
**Post date:** [February 11, 2019, 9:24am UTC](https://forum.litium.com/t/productmodel-getvalue-throws-on-some-products/579/1 "2019-02-11T09:24:03Z")

</div>

Hi, we have updated our database from 6.2 to 7.1 but on some products, the productModel.GetValue throws InvalidCastException. Where am expecting a null or the Color, am guessing that the data is “malformated”? Any suggestions on how to fix this without a lot of catching in the builder?

var color = productModel.GetValue(“Color”);

System.InvalidCastException: ‘Det gick inte att omvandla ett objekt av typen System.Collections.ObjectModel.ReadOnlyCollection`1[System.String] till typen System.String.’

Litium version: 7.1

---

<div class="post-metadata">

**Author:** ![patric.forsgard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/patric.forsgard/32/10_2.png) [@patric.forsgard](https://forum.litium.com/u/patric.forsgard)\
**Post date:** [February 11, 2019, 9:33am UTC](https://forum.litium.com/t/productmodel-getvalue-throws-on-some-products/579/2 "2019-02-11T09:33:53Z")

</div>

> [@Robin.w](#):
>
> productModel.GetValue(“Color”);

The `GetValue` method need to have the type specified to be able to return the value.

```auto
productModel.GetValue<IList<string>>("Color");

```

---

<div class="post-metadata">

**Author:** ![Robin.w](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/robin.w/32/75_2.png) [@Robin.w](https://forum.litium.com/u/Robin.w)\
**Post date:** [February 11, 2019, 10:30am UTC](https://forum.litium.com/t/productmodel-getvalue-throws-on-some-products/579/3 "2019-02-11T10:30:06Z")

</div>

Sorry, this was a bad code snippet to simplify. I’m using the default code from 7.1 Accelerator

return new ProductItemViewModel  
{  
Id = productModel.SelectedVariant.Id,  
Price = productPriceModel,  
StockStatusDescription = \_stockService.GetStockStatusDescription(productModel.SelectedVariant),  
Currency = currency,  
IsInStock = \_stockService.HasStock(productModel.SelectedVariant),  
Images = productModel.GetValue\<IList\>(SystemFieldDefinitionConstants.Images).MapTo\<IList\>(),  
**Color = \_fieldDefinitionService.Get(“Color”).GetTranslation(productModel.GetValue(“Color”)),**

But this should be updated to \<IList\<string\>\>?

---

<div class="post-metadata">

**Author:** ![Spotonkastebo](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/spotonkastebo/32/717_2.png) [@Spotonkastebo](https://forum.litium.com/u/Spotonkastebo)\
**Post date:** [February 11, 2019, 11:09am UTC](https://forum.litium.com/t/productmodel-getvalue-throws-on-some-products/579/4 "2019-02-11T11:09:28Z")

</div>

The accelerator has no support for multiple values in field color from what i have seen.  
The variant selection for variant is based on that you have one color and one size on an article.

> [@patric.forsgard](#):
>
> > productModel.GetValue(“Color”);
> 
> The `GetValue` method need to have the type specified to be able to return the value.

---

<div class="post-metadata">

**Author:** ![patric.forsgard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/patric.forsgard/32/10_2.png) [@patric.forsgard](https://forum.litium.com/u/patric.forsgard)\
**Post date:** [February 11, 2019, 11:41am UTC](https://forum.litium.com/t/productmodel-getvalue-throws-on-some-products/579/5 "2019-02-11T11:41:54Z")

</div>

The answer will be _it’s depend_

- If the `TextOption` does support multiple values you need to use `GetValue<ILIst<string>>("Color")`
- if the `TextOption` does **not** support multiple values you need to use `GetValue<string>("Color")`

Default accelerator the field is not supporting multiple values.

_To get nicer formatted code, use single backtick ``` to start/end inline code and tripple backtick ````` on separate line to start/end code block._
