简体   繁体   English

Azure移动服务.Net后端计划程序错误

[英]Azure Mobile Services .Net Backend Scheduler Error

I am writing a mobile service scheduler in my mobile service .net backend source . 我在我的移动服务.net后端源中编写了一个移动服务调度程序。

When I debug my app, when program calls Controller's getAll() method, get an exception. 当我调试应用程序时,当程序调用Controller的getAll()方法时,将获得异常。 The message is 消息是

"Object reference not set to an instance of an object." “你调用的对象是空的。”

I have a Model named Source, and also have a Controller name SourceController. 我有一个名为Source的模型,也有一个控制器名称SourceController。

SourceController sourceController = new SourceController();
List<Source> sources = new List<Source>();
sources = sourceController.GetAllSource().ToList();

At the line 3, I get this Error : 在第3行,出现此错误:

"Object reference not set to an instance of an object." “你调用的对象是空的。”

I ain't did any changes in Sources controller class. 我没有在Sources控制器类中进行任何更改。 This means in Visual Studio I clicked and add Controller to Source. 这意味着在Visual Studio中,我单击并将Controller添加到Source。 Also ain't did any changes in DataContext. 在DataContext中也没有做任何更改。

Can anybody help? 有人可以帮忙吗?

Unless you are doing unit testing you won't instantiate the controller directly -- it is initialized when a request comes in for an action within the controller. 除非您要进行单元测试,否则您不会直接实例化控制器-当在控制器内请求执行操作时,它将初始化。

If you are writing a test then note that your "sources" list isn't assigned to anything so it looks like SourceController.GetAllSource() gets a null source and hence ToList() will fail with the null exception that you see. 如果要编写测试,请注意您的“源”列表未分配任何内容,因此SourceController.GetAllSource()看起来像是一个空源,因此ToList()将失败,并出现空异常。

Hope this helps, 希望这可以帮助,

Henrik 亨里克

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM