Last post Mar 28, 2010 06:37 PM by hiyakaru
Mar 28, 2010 11:49 AM|hiyakaru|LINK
Well basically im having a problem in this line below
CartItem = CType(CartEntry.Value, CartItem)
It says - Unable to cast object of type 'CartItem' to type 'CartItem'.
This is the public cart item coding
Public Class CartItem Public Product As Productpage Public Quantity As IntegerEnd Class
and this is my display cart item class
Private Sub DisplayCart() ListBox1.Items.Clear() Dim CartItem As CartItem Dim CartEntry As DictionaryEntry For Each CartEntry In Cart CartItem = CType(CartEntry.Value, CartItem) ListBox1.Items.Add(CartItem.Display) Next End Sub
Thanks for help in advance
Mar 28, 2010 11:59 AM|Geckex|LINK
Hey - could you post the full exception - you'd normally get the full qualified type of each object on exceptions like this one.
Alternatively - have you tried attaching the debugger (or just running in debug mode) and then force the error to happen - if you have your VS set to break on exceptions (in debug -> Exceptions -< Common Language Runtime -> then select ur language which
looks like VB) you shoudl be able to then hover over the objects with your mouse pointer and inspect what you're trying to cast.
Mar 28, 2010 12:11 PM|hiyakaru|LINK
Here's the exception
System.InvalidCastException was unhandled by user code
Message="Unable to cast object of type 'CartItem' to type 'CartItem'."
at Cart.DisplayCart() in C:\Users\CoLdANg3L\Documents\Visual Studio 2008\WebSites\WebSite3\Cart.aspx.vb:line 28 at Cart.Page_Load(Object sender, EventArgs e) in C:\Users\CoLdANg3L\Documents\Visual Studio 2008\WebSites\WebSite3\Cart.aspx.vb:line 12
at System.Web.UI.Control.OnLoad(EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
and an additional info, this happens whenever i try to continue to the cart page with a quantity inserted into my product page
Mar 28, 2010 12:33 PM|Geckex|LINK
Hey - try and debug this - I am guessing you might have a null object or maybe you have CartItem defined more than once in different namespaces - try and do the debugging as described above and let us know the full types of both the object it's trying to
case - and the type it's trying to cast it to.
You should be able to get both by doing the hovering as described above.
Mar 28, 2010 06:37 PM|hiyakaru|LINK
thank you for making me checkin upon variables, double checked and found some overlapping, it works fine now!thanks alot! :)