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 |
![]() |
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 |
![]() |
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
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_UsersInRoleswhere ui.RoleId.ToString() == ((aspnet_Role)e.Row.DataItem).RoleId.ToString() select new { UserId = ui.UserId }; var users = from u in db.aspnet_Usersjoin 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 |
![]() |
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 |
![]() |