Quantcast
Channel: Task Scheduler Managed Wrapper
Viewing all articles
Browse latest Browse all 2206

Commented Unassigned: RegisterTaskDefinition() with TaskCreation.ValidateOnly parameter throws NullReferenceException [11681]

$
0
0
I noticed a strange error today when attempting to use the RegisterTaskDefinition() method from the TaskFolder class. If I use this overload:

```
RegisterTaskDefinition(string path, TaskDefinition definition, TaskCreation creationOption, string UserName)
```

Then I get a NullReferenceException. The portion of the stacktrace that shows where the problem is as follows:

```
System.NullReferenceException was unhandled
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=Microsoft.Win32.TaskScheduler
StackTrace:
at Microsoft.Win32.TaskScheduler.Task.GetV2Definition(TaskService svc, IRegisteredTask iTask, Boolean throwError)
at Microsoft.Win32.TaskScheduler.Task.CreateTask(TaskService svc, IRegisteredTask iTask, Boolean throwError)
at Microsoft.Win32.TaskScheduler.TaskFolder.RegisterTaskDefinition(String Path, TaskDefinition definition, TaskCreation createType, String UserId, String password, TaskLogonType LogonType, String sddl)
at MYAPPLIATION.GUI.SchedulingManager.addTaskButton_Click(Object sender, EventArgs e) in MYAPPLICATION\GUI\SchedulingManager.cs:line 175
```

If I remove the TaskCreation enum option and the username to use the overload that is only Name & Definition, then there are no issues. The option that I'm using is TaskCreation.ValidateOnly option since I don't want to actually register the task just yet.
Comments: ** Comment from web user: JNYRanger **

Thanks for the info. I actually didn't really want to validate, I just was looking for a method to create a task object to send to the TaskSchedulerEditor UI that was not registered, but 99% of it is already pre-populated. I then wanted to use the definition from the TaskSchedulerEditor as the one that actually gets registered. Now that I'm typing this out I just thought of a much better way to handle this anyway, but I'm glad that's fixed either way!


Viewing all articles
Browse latest Browse all 2206

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>