odd nullreference error at foreach when rendering view

Posted by giddy on Stack Overflow See other posts from Stack Overflow or by giddy
Published on 2010-12-23T11:04:21Z Indexed on 2010/12/23 11:54 UTC
Read the original article Hit count: 247

This error is so weird I Just can't really figure out what is really wrong!

In UserController I have

public virtual ActionResult Index()
{
    var usersmdl = from u in RepositoryFactory.GetUserRepo().GetAll()
                   select new UserViewModel
                   {
                       ID = u.ID,
                       UserName = u.Username,
                       UserGroupName = u.UserGroupMain.GroupName,
                       BranchName = u.Branch.BranchName,
                       Password = u.Password,
                       Ace = u.ACE,
                       CIF = u.CIF,
                       PF = u.PF
                   };
    if (usersmdl != null)
    {
        return View(usersmdl.AsEnumerable());
    }
    return View();
}

My view is of type @model IEnumerable<UserViewModel> on the top.
This is what happens:

alt text

Where and what exactly IS null!?

I create the users from a fake repository with moq. I also wrote unit tests, which pass, to ensure the right amount of mocked users are returned.

Maybe someone can point me in the right direction here? Top of the stack trace is :

at lambda_method(Closure , User )
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at ASP.Index_cshtml.Execute() 

Is it something to do with linq here? Tell me If I should include the full stack trace.

© Stack Overflow or respective owner

Related posts about c#

Related posts about asp.net-mvc