Unable to cast object of type '<>f__AnonymousType1`3[System.Guid,System.String,System.String]' to type 'aspnet_User'.???

Hi everyone,

What does this error mean? 

ERROR: Unable to cast object of type '<>f__AnonymousType1`3[System.Guid,System.String,System.String]' to type 'aspnet_User'.

Thank's a lot

/Pepe


Pepe Jose
Newbie@C#.Net&jRuby
0
pepejose63
2/10/2008 7:28:52 PM
asp.net.getting-started 91979 articles. 4 followers. Follow

3 Replies
2202 Views

Similar Articles

[PageSpeed] 18
Get it on Google Play
Get it on Apple App Store

What type is in your DataItem?  A Guid? or a String?  Either way, it's telling you cant cast it to a aspnet_User type.  Let us know what your DataItem is and we can help further.


Good Luck and happy programming!

Let's build community! If my post helped you, mark it as the Answer and I will do the same
when you help me...this will help everybody!
0
dtrent
2/10/2008 8:40:19 PM

Hi,

Thank you for your reply. I have a master gridview and a details gridview. As you can see in next few lines I try to DataBound data from the aspnet_Users to Rows in the masterGridview.  Of course using UsersInRoles to find right members for each role.

I think the error is about the where statement in first linq query, bu still can't see what's wrong Confused

protected void XGridUsersInRolesMaster_RowDataBound(object sender, GridViewRowEventArgs e)

{

if (e.Row.RowType == DataControlRowType.DataRow)

{

GridView gv = (GridView)e.Row.FindControl("GridViewUsersInRolesDetails");

DataContext_SecurityDataContext db = new DataContext_SecurityDataContext();

var userIds = from ui in db.aspnet_UsersInRoles

where ui.RoleId.ToString() == ((aspnet_Role)e.Row.DataItem).RoleId.ToString()

select new { UserId = ui.UserId };

var users = from u in db.aspnet_Users

join ui in userIds

on u.UserId equals ui.UserId

select new { ID = u.UserId, Name = u.UserName };

//System.InvalidCastException was unhandled by user code

//Message="Unable to cast object of type '<>f__AnonymousType1`3[System.Guid,System.String,System.String]' to type 'aspnet_Role'."

//Source="System.Data.Linq"

gv.DataSource = users;

gv.DataBind();

}

}

My first post had too many code error. This one is what I want to do. But still same error message...

Thank's,

/Pepe


Pepe Jose
Newbie@C#.Net&jRuby
0
pepejose63
2/11/2008 10:33:13 AM

Hi,

Could you please check what value “e.Row.DataItem” is in the debug mode? How did you bind your master GridView, using aspnet_Users table? If so, the e.Row.DataItem should be aspnet_Users entity.

 


If this doesn’t help you, please feel free to let me know.


I hope this helps.

 


Thomas Sun
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
0
Thomas
2/13/2008 4:17:53 AM
Reply: