简体   繁体   中英

Azure Mobile Services .Net Backend Scheduler Error

I am writing a mobile service scheduler in my mobile service .net backend source .

When I debug my app, when program calls Controller's getAll() method, get an exception. 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.

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

At the line 3, I get this Error :

"Object reference not set to an instance of an object."

I ain't did any changes in Sources controller class. This means in Visual Studio I clicked and add Controller to Source. Also ain't did any changes in 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.

Hope this helps,

Henrik

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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