London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!
London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!
It seems that the item that is referenced through "itemLink" is an instance of type "ProductContent" while your call to contentLoader
loader.Get<PreciousMetalsSKU>(itemLink, new LanguageSelector(language));
expect it to be an instance of PreciousMetalsSKU and apparantely cant ProductContent be casted to PreciousMetalsSKU.
I am not sure if itemLink always is expected to be an instance of PreciousMetalsSKU , if not you could use "as" operator to check like:
var productSKU = loader.Get<IContent>(itemLink, new LanguageSelector(language)) as PreciousMetalsSKU; if (productSKU != null) { lineItem.ProductDescription = productSKU.DisplayName; }
The answer from Johan is indeed correct, but one more note: for performance reason you should not load the Entry (especially with Full response group) - it is an heavy task. You can just load the Dto and get the Id from there - or even use ReferenceConverter to do that.
Later version of Commerce optimized that further and made the conversion from Code to Id a fast and lightweight task. For that reason you should upgrade to latest version if possible. 7.12 is almost 4 years old now.
Definately just call referenceConverter.GetContentLink(lineItem.Code, CatalogContentType.CatalogEntry), (i assume the use of lineItem.CurrencyCode in your example is a mistype).
If you really are only after line items that is PreciousMetalsSKU you can call loader.TryGet<PreciousMetalsSku>().
Hi Team,
This is Arjun Katkojwala, i work for CGI. We have integrated EPI 7.11 to our applications. We are getting issues while getting Catalog details when calling below code. Can you please let us know why we are getting exception. becuase, due to this exception our application is getting down. Once we recycle app pool, this issue is getting resolved. Can you please let u know what is permanent solution to fix, so we can work on this get it resolved.
Code to retrieve Catalog Details:
string language = contact.PreferredLanguage;
var entry = CatalogContext.Current.GetCatalogEntry(lineItem.CurrencyCode, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));
if (entry != null)();();
{
IContentLoader loader = ServiceLocator.Current.GetInstance
var referenceConverter = ServiceLocator.Current.GetInstance
ContentReference itemLink = referenceConverter.GetContentLink(entry.CatalogEntryId,
CatalogContentType.CatalogEntry, 0);
var productSKU = loader.Get(itemLink, new LanguageSelector(language));
if (productSKU != null)
{
lineItem.ProductDescription = productSKU.DisplayName;
}
}
Exception Details:
2018-03-28 04:05:37,807 [27] INFO CIBC.OnlineBanking.Web.ECPServices [(null)] - RetrieveOrderDetails - lineItem.ProductDescription: 2018 Welcome to the World
2018-03-28 04:05:38,229 [27] ERROR CIBC.OnlineBanking.Web.ECPServices [(null)] - RetrieveOrderDetails Exception :
EPiServer.Core.TypeMismatchException: Content with id '208__CatalogContent' is of type 'Castle.Proxies.ProductContentProxy' which does not inherit required type 'Commerce.Models.PreciousMetalsSKU'
at EPiServer.Core.DefaultContentLoader.ThrowTypeMismatchException(ContentReference link, Type actual, Type required)
at EPiServer.Core.DefaultContentLoader.Get[T](ContentReference contentLink, LoaderSettings loaderSettings)
at EPiServer.Core.DefaultContentLoader.Get[T](ContentReference contentLink, ILanguageSelector selector)
at CIBC.OnlineBanking.Web.ECPServices.RetrieveOrderDetails(OrderDetailsRequest Request)
2018-03-28 04:05:38,229 [27] ERROR CIBC.OnlineBanking.Web.ECPServices [(null)] - RetrieveOrderDetails Exception Message : Content with id '208__CatalogContent' is of type 'Castle.Proxies.ProductContentProxy' which does not inherit required type 'Commerce.Models.PreciousMetalsSKU'
2018-03-28 04:05:38,229 [27] ERROR CIBC.OnlineBanking.Web.ECPServices [(null)] - RetrieveOrderDetails Exception - Stack Trace: at EPiServer.Core.DefaultContentLoader.ThrowTypeMismatchException(ContentReference link, Type actual, Type required)
at EPiServer.Core.DefaultContentLoader.Get[T](ContentReference contentLink, LoaderSettings loaderSettings)
at EPiServer.Core.DefaultContentLoader.Get[T](ContentReference contentLink, ILanguageSelector selector)
at CIBC.OnlineBanking.Web.ECPServices.RetrieveOrderDetails(OrderDetailsRequest Request)