[RESOLVED]Method giving NullReferenceException in one class but working well everywhere else

I'm using a method which is working well from all other references(other classes) except this one. I fail to understand why.

public class WorkerTaskController : Controller { // GET: WorkerTask private IWorkerTaskRepository repository; private IWorkerRepository repository_worker; // contains method definition of GetWorkers. Mapped using IOC Ninject public ActionResult AddWorkerTask() { var workerList = new WorkersViewModel();
IEnumerable<Worker> workers = repository_worker.GetWorkers(1); /* paramt value hardcoded */// Giving NullRefernceException
// Its working well everywhere else with same paramt value but throwing error here

workerList.WorkersList = workers.Select(x => new SelectListItem { Text = x.FirstName + " " + x.LastName}).ToList(); return View(); }


Clean the solution and rebuild it again, it might be an issue with reference class or assembly 

Thanks but that didn’t work :(

I was getting the error because I had forgotten to initialize the repository variable. Silly mistake!



Leave a Reply