I have this code to create a list from a foreach loop from membershipuser..
public List<UsersModels> _users;
MembershipUserCollection iduser = Membership.GetAllUsers();
foreach (MembershipUser member in iduser)
{
UsersModels usmodel = new UsersModels();
usmodel.Username = member.UserName;
usmodel.Email = member.Email;
usmodel.LastLoginDate = member.LastLoginDate;
usmodel.LastActivityDate = member.LastActivityDate;
_users.Add(usmodel); // BREAKPOINT
}
When I put a breakpoint at the bottom, I can see all the data is OK, but after adding the object (another object to the list) it tells:
Object reference not set to an instance of an object.
Here is the breakpoint showing that the data apparently is OK
http://i.imgbox.com/aafDt7MJ.png
Can someone tell me what can be wrong? I dont understand why the usmodel object has its data apparently OK, but cannot add it to the list showing the error above.
Thanks.