Dear All,

I've write custom shipping plugin that is displaying shipping price per item,this is working fine in admin but it displaying error on front page, here are the error message

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Unable to cast object of type 'System.Data.Entity.DynamicProxies.ShippingMethod_5DAB138817980862F8211E712C85A10B8C1CBD488C3E7DCCDC8EDE8C5DDEF719' to type 'System.Collections.Generic.ICollection`1[NopSolutions.NopCommerce.BusinessLogic.Shipping.ShippingMethod]'.

Source Error:

Line 160:                        where st.ps_ShippingMethodID == ShippingMethodID
Line 161:                        select st;
Line 162:            var collection = query.ToList(); HERE I'M GETTING AN ERROR
Line 163:            return collection;
Line 164:        }


Stack Trace:

[InvalidCastException: Unable to cast object of type 'System.Data.Entity.DynamicProxies.ShippingMethod_5DAB138817980862F8211E712C85A10B8C1CBD488C3E7DCCDC8EDE8C5DDEF719' to type 'System.Collections.Generic.ICollection`1[NopSolutions.NopCommerce.BusinessLogic.Shipping.ShippingMethod]'.]
   set_Nop_ShippingMethod(Object , Object ) +83
   System.Data.Objects.Internal.<>c__DisplayClass8.<CreateBaseSetter>b__7(Object entity, Object value) +72
   System.Data.Objects.Internal.PocoPropertyAccessorStrategy.SetNavigationPropertyValue(RelatedEnd relatedEnd, Object value) +192

[EntityException: Unable to set field/property Nop_ShippingMethod on entity type System.Data.Entity.DynamicProxies.ShippingbyProduct_551DAB6573AEE62486F6FBF45112FEFEAA2879CB5A73B590733C0BB6F3974F6F. See InnerException for details.]
   System.Data.Objects.Internal.PocoPropertyAccessorStrategy.SetNavigationPropertyValue(RelatedEnd relatedEnd, Object value) +284
   System.Data.Objects.Internal.EntityWrapper`1.SetNavigationPropertyValue(RelatedEnd relatedEnd, Object value) +23
   System.Data.Objects.DataClasses.EntityReference`1.AddToObjectCache(IEntityWrapper wrappedEntity) +44
   System.Data.Objects.DataClasses.RelatedEnd.Add(IEntityWrapper wrappedTarget, Boolean applyConstraints, Boolean addRelationshipAsUnchanged, Boolean relationshipAlreadyExists, Boolean allowModifyingOtherEndOfRelationship, Boolean forceForeignKeyChanges) +1434
   System.Data.Objects.DataClasses.RelatedEnd.Add(IEntityWrapper wrappedEntity, Boolean applyConstraints) +61
   System.Data.Objects.DataClasses.EntityReference`1.set_ReferenceValue(IEntityWrapper value) +290
   System.Data.Objects.DataClasses.EntityReference.SetEntityKey(EntityKey value, Boolean forceFixup) +590
   System.Data.Objects.EntityEntry.FixupEntityReferenceToPrincipal(EntityReference relatedEnd, EntityKey foreignKey, Boolean setIsLoaded, Boolean replaceExistingRef) +351
   System.Data.Objects.EntityEntry.FixupReferencesByForeignKeys(Boolean replaceAddedRefs) +356
   System.Data.Objects.ObjectStateManager.FixupReferencesByForeignKeys(EntityEntry newEntry, Boolean replaceAddedRefs) +125
   System.Data.Objects.ObjectStateManager.AddEntry(IEntityWrapper wrappedObject, EntityKey passedKey, EntitySet entitySet, String argumentName, Boolean isAdded) +378
   System.Data.Common.Internal.Materialization.Shaper.HandleEntityAppendOnly(Func`2 constructEntityDelegate, EntityKey entityKey, EntitySet entitySet) +323
   lambda_method(Closure , Shaper ) +202
   System.Data.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper) +175
   System.Data.Common.Internal.Materialization.SimpleEnumerator.MoveNext() +84
   System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +327
   System.Linq.Enumerable.ToList(IEnumerable`1 source) +58
   NopSolutions.NopCommerce.BusinessLogic.Shipping.ShippingByProductService.GetShippingValueByID(Int32 CountryID, Int32 ProductID, Int32 ShippingMethodID) in E:\aspdotnet\Triskom\Libraries\Nop.BusinessLogic\Shipping\ShippingByProductService.cs:162
   NopSolutions.NopCommerce.Shipping.Methods.ShippingByProductCM.ShippingByProductComputationMethod.GetRate(Int32 CountryID, Int32 ProductID, Int32 ShippingMethodId) in E:\aspdotnet\Triskom\Shipping\Nop.Shipping.ShippingByProduct\ShippingByProductComputationMethod.cs:28
   NopSolutions.NopCommerce.Shipping.Methods.ShippingByProductCM.ShippingByProductComputationMethod.GetShippingOptions(ShipmentPackage shipmentPackage, String& error) in E:\aspdotnet\Triskom\Shipping\Nop.Shipping.ShippingByProduct\ShippingByProductComputationMethod.cs:132
   NopSolutions.NopCommerce.BusinessLogic.Shipping.ShippingService.GetShippingOptions(ShoppingCart cart, Customer customer, Address shippingAddress, Nullable`1 allowedShippingRateComputationMethodId, String& error) in E:\aspdotnet\Triskom\Libraries\Nop.BusinessLogic\Shipping\ShippingService.cs:1012
   NopSolutions.NopCommerce.BusinessLogic.Shipping.ShippingService.GetShippingOptions(ShoppingCart cart, Customer customer, Address shippingAddress, String& error) in E:\aspdotnet\Triskom\Libraries\Nop.BusinessLogic\Shipping\ShippingService.cs:971
   NopSolutions.NopCommerce.Web.Modules.CheckoutShippingMethodControl.BindData() in E:\aspdotnet\Triskom\NopCommerceStore\Modules\CheckoutShippingMethod.ascx.cs:138
   NopSolutions.NopCommerce.Web.CheckoutShippingMethodPage.Page_Load(Object sender, EventArgs e) in E:\aspdotnet\Triskom\NopCommerceStore\CheckoutShippingMethod.aspx.cs:61
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +91
   NopSolutions.NopCommerce.Web.BaseNopFrontendPage.OnLoad(EventArgs e) in E:\aspdotnet\Triskom\NopCommerceStore\Controls\BaseNopFrontendPage.cs:147
   System.Web.UI.Control.LoadRecursive() +74

Could anyone please guide me how to resolve this error?

Thanks in Advance
Hitesh