v2Folder and definition.v1Task are null

Mar 28, 2012 at 4:48 PM

Hi, first timer here; thanks for this great component!

On Windows 7, if I create a new task, re-open it using the GetTask() method, and load it in the task editor, I get a null reference exception after clicking OK on the task editor dialog.

Object reference not set to an instance of an object.

-------------------------- Technical Information Follows --------------------------

Exception Details: ----------------------------------------

Exception type: System.NullReferenceException
Message: Object reference not set to an instance of an object.
Source: Microsoft.Win32.TaskScheduler
Target Site: RegisterTaskDefinition
Stack Trace:
at Microsoft.Win32.TaskScheduler.TaskFolder.RegisterTaskDefinition(String Path, TaskDefinition definition, TaskCreation createType, String UserId, String password, TaskLogonType LogonType, String sddl) in C:\Users\aubang\Downloads\TaskScheduler\TaskService\TaskFolder.cs:line 248
at Microsoft.Win32.TaskScheduler.TaskFolder.RegisterTaskDefinition(String Path, TaskDefinition definition) in C:\Users\aubang\Downloads\TaskScheduler\TaskService\TaskFolder.cs:line 226 at Microsoft.Win32.TaskScheduler.Task.RegisterChanges() in C:\Users\aubang\Downloads\TaskScheduler\TaskService\Task.cs:line 821
at Microsoft.Win32.TaskScheduler.TaskEditDialog.okBtn_Click(Object sender, EventArgs e) in C:\Users\aubang\Downloads\TaskScheduler\TaskService\TaskEditor\TaskEditDialog.cs:line 209

Thanks for any ideas or help.

Audi

 

 

 

 

Coordinator
Mar 28, 2012 at 5:16 PM

My guess is that you are disposing some part of the task before the dialog is able to process the changes. Check your code and if you are still having problems, feel free to post it so we can help you troubleshoot it.

Mar 28, 2012 at 6:14 PM
Edited Mar 28, 2012 at 6:15 PM

Thanks for the swift reply!

I noticed that if I open an existing task using the task editor with the RegisterTaskOnAccept property set to true, I get the null reference exception when I click on the OK button.

If I set the RegisterTaskOnAccept property to false, I don't get the null reference exception, but noticed that if I make some edits (say, to the task Description), and click Cancel, the edits get saved. Should I be calling some method(s) here?

Thanks again.

 

Coordinator
Mar 28, 2012 at 10:40 PM

The RegisterTaskOnAccept property controls whether the task is re-registered when the user clicks the Ok/Finish button on the form. Your changes will only be applied if the task is re-registered either by setting that property or manually calling TaskFolder.RegisterTaskDefinition. I would still guess your problem lies in the task being disposed before you enter the editor.

Mar 29, 2012 at 2:23 PM

David, thanks, your guess was 100% correct! :-) Everything is now working flawlessly. Thanks again and have a great day!