0

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.

1 Answer 1

6

You have not initialized the _users variable. Therefore, _users.Add() is throwing an error

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Mike, i have spend much time to try to fix it, and i havent see where is wrong..Thanks again!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.