English 中文(简体)
C# 中对象实例未设置对象引用
原标题:Object reference not set to an instance of an object in C#

我正在开发一个 asp.net MVC 2. 0 的应用程序,其中我正在调用控制器中 < code > Rectory 的功能,但它给了我一个例外,即 < code> Object reference 不设置为对象的示例 , 它不允许我调试这条线,所以我找不到问题。 这是代码 。

private IIssueRepository _issueRepository;

public double CalculateLoadBar(long userID)
{
    int i = 0;
    double load = 0;
    var issues = _issueRepository.GetAssignedIssues(userID);
}

请告诉我如何找出问题,谢谢

最佳回答

从您张贴的内容来看, 似乎没有设置为对象 - 它不会在任何地方被即时激活 。

它需要被即时处理,然后才能调用方法。

问题回答

在使用此对象前尝试即时处理该对象, 就像在下面 :

_issueRepository = new IssueRepository();

希望这一帮助。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签