SaaS CMS has officially launched! Learn more now.

Invalid cast in Commerce Manager after update from 11.2.5 to 11.8.5


Hi all,

After upgrading from Commerce 11.2.5 to 11.8.5, which should not contain any breaking change, we get the following error in Commerce Manager when trying to create a return. Anyone seen this error? Is this an undocumented breaking change?

[InvalidCastException: Unable to cast object of type 'EPiServer.Commerce.Order.Internal.InMemoryShipment' to type 'Mediachase.Commerce.Orders.Shipment'.]
EPiServer.Commerce.Order.Calculator.DefaultShippingCalculator.GetShippingRate(IShipment shipment, ShippingMethodRow row, IMarket market) +282
EPiServer.Commerce.Order.Calculator.DefaultShippingCalculator.CalculateShippingCost(IShipment shipment, IMarket market, Currency currency) +575
EPiServer.Commerce.Order.Calculator.DefaultShippingCalculator.GetDiscountedShippingAmount(IShipment shipment, IMarket market, Currency currency) +388
EPiServer.Commerce.Order.Calculator.DefaultTaxCalculator.CalculateShippingTaxTotal(IShipment shipment, IMarket market, Currency currency, Func`3 getShippingTotalFunc, Func`3 getDiscountedPriceFunc, Boolean isReturn) +311
EPiServer.Commerce.Order.Calculator.DefaultTaxCalculator.CalculateShippingTaxTotal(IShipment shipment, IMarket market, Currency currency) +259
EPiServer.Commerce.Order.Calculator.DefaultTaxCalculator.GetShippingTaxTotal(IShipment shipment, IMarket market, Currency currency) +367
EPiServer.Commerce.Order.Calculator.<>c__DisplayClass7_0.<GetTotalForReturns>b__1(IShipment shipment) +157
System.Linq.WhereSelectEnumerableIterator`2.MoveNext() +233
System.Linq.Enumerable.Sum(IEnumerable`1 source) +98
EPiServer.Commerce.Order.Calculator.DefaultReturnPurchaseOrderCalculator.GetTotalForReturns(IPurchaseOrder order) +788
EPiServer.Commerce.Order.Calculator.DefaultReturnPurchaseOrderCalculator.CalculateReturnTotal(IPurchaseOrder purchaseOrder, IReturnOrderForm currentReturnForm, Boolean isCompletingReturnForm) +338
Mediachase.Commerce.Manager.Apps.Order.Modules.OrderCreateReturn.CalculateReturnTotal() +147
Mediachase.Commerce.Manager.Apps.Order.Modules.OrderCreateReturn.Page_Load(Object sender, EventArgs e) +1241
System.Web.UI.Control.OnLoad(EventArgs e) +106
System.Web.UI.Control.LoadRecursive() +68
System.Web.UI.Control.LoadRecursive() +162
System.Web.UI.Control.LoadRecursive() +162
System.Web.UI.Control.LoadRecursive() +162
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3785

Feb 01, 2019 12:15

It sounds like your shipment has the wrong shipping gateway/plugin attached. It should have been a class that implements IShippingPlugin, but it only implements IShippingGateway 

Feb 01, 2019 12:22

Hi Quan. When did this change? It seems it stopped working for us when going from 11.2.5 to 11.8.5.

Feb 01, 2019 12:50

I can't recall any change related to this. Which is the shipping method attached to this shipment. What does the implementation of that shipping method look like? 

Feb 01, 2019 12:55

It is a custom gateway which implements IShippingGateway. The invalid cast occurs in GetRate() since it expects a Shipment but gets an IShipment.

I'll try to change the implementation but one thing occured to me. We rely on data from the orderform and ordergroup which we get from LineItem.Parent and LineItem.Parent.Parent. I don't see any replacement for that in IShipment. How can we resolve which OrderForm an IShipment belongs to?

Feb 01, 2019 13:15

Hmm, what does your CM Configs\ look like 

Feb 01, 2019 13:30

<?xml version="1.0" encoding="utf-8"?>
<Application defaultApplicationName="xxxxx.CommerceAdmin">
<add name="AdminRole" value="Admins"/>
<add name="ManagerUserRole" value="Management Users"/>
<add name="EveryoneRole" value="Everyone"/>
<add name="RegisteredRole" value="Registered"/>
<Connection connectionStringName="EcfSqlConnection"/>
<Cache enabled="true" appTimeout="0:0:10"/>
<add key="en-us" value="English"/>
<add key="da-DK" value="Danish"/>
<add key="sv-SE" value="Svenska"/>
<add key="fi-FI" value="Suomi"/>
<add key="nl-NL" value="Netherlands"/>
<add key="nb-NO" value="Norsk"/>
<add key="fr-FR" value="French"/>
<add feature="WorkflowsVNext" state="Disabled" type="Mediachase.Commerce.Core.Features.WorkflowsVNext, Mediachase.Commerce"/>

Feb 01, 2019 13:32

Shouldn't it be Enabled for WorkflowsVNext

Feb 01, 2019 13:34

We're still on the old promotion system.

Feb 01, 2019 13:40

Please reach out for developer support service, and we can take it from there 

Feb 01, 2019 14:01

HI Quan

Did you get to the bottom of this. We seem to ebe getting the same error when trying to do a return in commerce manager.



Jan 21, 2021 17:26

Unfortunately no - or if we did - I forget it now. Please reach out to developer support service 

Jan 22, 2021 9:04
* 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.