I wrote an c# console app which calls web service.
I needed to run this app for every night, so I decided to use this task scheduler as it seems a good one to do my job.
But I got an issue which says "Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object. ..."
I read many articles described about same issue, but nothing is helpful.
For example,
```
TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = "Does something";
td.Principal.Id = "any string";
td.Principal.GroupId = "NETWORK SERVICE";
td.Principal.RunLevel = TaskRunLevel.LUA;
td.Principal.LogonType = TaskLogonType.S4U;
ts.RootFolder.RegisterTaskDefinition(@"NetsuiteInvoiceGetTask", td);
```
My OS is Windows7 64bit.
Can anyone help me? Thanks.
Comments: ** Comment from web user: dahall **
I needed to run this app for every night, so I decided to use this task scheduler as it seems a good one to do my job.
But I got an issue which says "Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object. ..."
I read many articles described about same issue, but nothing is helpful.
For example,
```
TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = "Does something";
td.Principal.Id = "any string";
td.Principal.GroupId = "NETWORK SERVICE";
td.Principal.RunLevel = TaskRunLevel.LUA;
td.Principal.LogonType = TaskLogonType.S4U;
ts.RootFolder.RegisterTaskDefinition(@"NetsuiteInvoiceGetTask", td);
```
My OS is Windows7 64bit.
Can anyone help me? Thanks.
Comments: ** Comment from web user: dahall **
At what line are you getting the exception? Some other things: RunLevel defaults to LUA. TaskLogonType.S4U is reserved for user accounts. I, personally, would eliminate the GroupID, RunLevel and LogonType lines from your code and just call the RegisterTaskDefinition as outlined [here](https://taskscheduler.codeplex.com/wikipage?title=TaskSecurity&referringTitle=Documentation#system).