Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
| Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 11th, 2016, 06:03 AM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2016
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 14 Unable to cast object of type exception

Hi,

below is my code
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PlanetWroxModel;



public partial class NewPhotoAlbum : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void EntityDataSource1_Inserted(object sender, EntityDataSourceChangedEventArgs e)
    {
        PhotoAlbum myPhotoAlbum = (PhotoAlbum)e.Entity;
        Response.Redirect(string.Format("ManagePhotoAlbum.aspx?PhotoAlbumId={0}", myPhotoAlbum.Id.ToString()));
    }
}
I get a "Invalid Cast Exception was unhandled by user code" error
i.e
{"Unable to cast object of type 'PlanetWroxModel.PhotoAlbum' to type 'PhotoAlbum'."}
At:
Code:
PhotoAlbum myPhotoAlbum = (PhotoAlbum)e.Entity;
Could someone please explain why and how I can fix this issue.

Cheers.
 
Old December 12th, 2016, 11:06 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Sounds like yo have another class called PhotoAlbum somewhere. Do you have a page called PhotoAlbum maybe or another class in App_Code?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old December 14th, 2016, 08:00 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2016
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Imar View Post
Sounds like yo have another class called PhotoAlbum somewhere. Do you have a page called PhotoAlbum maybe or another class in App_Code?

Imar
Hi Imar thanks for your reply.

No I do not have another class or page called PhotoAlbum somewhere else.

When I click 'Insert' the underhanded exception error occurs but the data gets inserted in the Database.

I Also get this message:
An exception of type 'System.InvalidCastException' occurred in App_Web_y5wab1hk.dll but was not handled in user code

Additional information: Unable to cast object of type 'PlanetWroxModel.PhotoAlbum' to type 'PhotoAlbum'

Noel

Last edited by nkiuk; December 14th, 2016 at 08:12 PM..
 
Old December 15th, 2016, 09:00 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

>> No I do not have another class or page called PhotoAlbum somewhere else.

To see if that's really true, click on the first PhotoAlbum in this line:

PhotoAlbum myPhotoAlbum = (PhotoAlbum)e.Entity;

and then press F12. Where does it take you?
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old July 28th, 2018, 03:06 AM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2018
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Full

Quote:
Originally Posted by nkiuk View Post
Hi,

below is my code
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PlanetWroxModel;



public partial class NewPhotoAlbum : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void EntityDataSource1_Inserted(object sender, EntityDataSourceChangedEventArgs e)
    {
        PhotoAlbum myPhotoAlbum = (PhotoAlbum)e.Entity;
        Response.Redirect(string.Format("ManagePhotoAlbum.aspx?PhotoAlbumId={0}", myPhotoAlbum.Id.ToString()));
    }
}
I get a "Invalid Cast Exception was unhandled by user code" error
i.e
{"Unable to cast object of type 'PlanetWroxModel.PhotoAlbum' to type 'PhotoAlbum'."}
At:
Code:
PhotoAlbum myPhotoAlbum = (PhotoAlbum)e.Entity;
Could someone please explain why and how I can fix this issue.

Cheers.
Can you show me full of code




Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 14 - Unable to list DB from the given sample program. RedGuy BOOK: Beginning Object-Oriented Programming with C# 9 December 16th, 2014 08:10 PM
Ch4 unable to cast object of type asp.default_aspx to type basepage Dex69 BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio 0 July 5th, 2011 05:04 PM
Unable to cast object of type 'TheBeerHouseSection DyerOppenheimer BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 4 June 10th, 2008 12:13 PM
Receiving Error Msg:Unable to cast object of type cesemj ASP.NET 2.0 Basics 2 March 4th, 2008 02:18 PM
Unable to cast object of type galua SQL Language 3 January 9th, 2008 01:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.