[英]Object reference not set to an instance of an object in C#
I am developing an application in asp.net MVC 2.0 in which I am calling the function of Repository
in controller but it is giving me an exception of Object reference not set to an instance of an object
and Its not allowing me to debug this line so I am unable to find the Problem. 我正在asp.net MVC 2.0中开发一个应用程序,在该应用程序中我在控制器中调用
Repository
的功能,但它给了我一个例外,即Object reference not set to an instance of an object
并且它不允许我调试此行,因此我找不到问题。 Here is the code. 这是代码。
private IIssueRepository _issueRepository;
public double CalculateLoadBar(long userID)
{
int i = 0;
double load = 0;
var issues = _issueRepository.GetAssignedIssues(userID);
}
Please tell me how to trace out the problem. 请告诉我如何找出问题所在。 Thanks
谢谢
From what you posted, it appears that _issueRepository
is not set to an object - it is not instantiated anywhere. 从您发布的内容来看,似乎
_issueRepository
未设置为对象-不会在任何地方实例化。
It needs to be instantiated before you can call methods on it. 需要先实例化它,然后才能在其上调用方法。
Try instantiate this object before use it like following : 尝试实例化该对象,然后使用它,如下所示:
_issueRepository = new IssueRepository();
hope this help. 希望有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.