View Single Post
  #1 (permalink)  
Old December 11th, 2016, 06:03 AM
nkiuk nkiuk is offline
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