Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old December 11th, 2016, 05: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.
Reply With Quote
  #2 (permalink)  
Old December 12th, 2016, 10:06 AM
Imar's Avatar
Wrox Author
Points: 71,154, Level: 100
Points: 71,154, Level: 100 Points: 71,154, Level: 100 Points: 71,154, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,944
Thanks: 79
Thanked 1,554 Times in 1,531 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!
Reply With Quote
  #3 (permalink)  
Old December 14th, 2016, 07: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 07:12 PM.
Reply With Quote
  #4 (permalink)  
Old December 15th, 2016, 08:00 AM
Imar's Avatar
Wrox Author
Points: 71,154, Level: 100
Points: 71,154, Level: 100 Points: 71,154, Level: 100 Points: 71,154, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,944
Thanks: 79
Thanked 1,554 Times in 1,531 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!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 07: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 01:18 PM
Unable to cast object of type galua SQL Language 3 January 9th, 2008 12:31 PM



All times are GMT -4. The time now is 11:43 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.