TaskEditorDialog.Initialize throws NullReferenceException

Jun 27, 2010 at 7:09 PM

Using VS2010 in XP. Created example code:

Snippet

			using (TaskService ts = new TaskService())
{


const string taskName = "Test";
Task t = ts.AddTask(taskName,
   new TimeTrigger() { StartBoundary = DateTime.Now + TimeSpan.FromHours(1), Enabled = false },
   new ExecAction("notepad.exe""c:\\test.log""C:\\"));

// Edit task and re-register if user clicks Ok
TaskEditDialog editorForm = new TaskEditDialog();
editorForm.Editable = true;
editorForm.Initialize(t);
if (editorForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
ts.RootFolder.RegisterTaskDefinition(taskName, editorForm.TaskDefinition);
}

// Remove the task we just created
ts.RootFolder.DeleteTask(taskName);

}

Executing editorForm.Initialize(t) throws the following exception:

System.NullReferenceException was unhandled
  Message=Object reference not set to an instance of an object.
  Source=Microsoft.Win32.TaskScheduler
  StackTrace:
       at Microsoft.Win32.TaskScheduler.TaskService.ShouldSerializeUserName()
       at Microsoft.Win32.TaskScheduler.TaskService.get_UserName()
       at Microsoft.Win32.TaskScheduler.TaskPropertiesControl.set_TaskDefinition(TaskDefinition value)
       at Microsoft.Win32.TaskScheduler.TaskPropertiesControl.set_Task(Task value)
       at Microsoft.Win32.TaskScheduler.TaskPropertiesControl.Initialize(Task task)
       at Microsoft.Win32.TaskScheduler.TaskEditDialog.Initialize(Task task)
       at TIRATool.MainForm.ScheduleButton_Click(Object sender, EventArgs e) in F:\SoftSys\Projects\TIRA TV Control\TIRATool\TIRATool\MainForm.cs:line 264
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at TIRATool.Program.Main(String[] args) in F:\SoftSys\Projects\TIRA TV Control\TIRATool\TIRATool\Program.cs:line 25
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
       at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
       at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
       at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
       at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
       at System.Activator.CreateInstance(ActivationContext activationContext)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:


Jul 2, 2010 at 12:14 AM

Try this:

When instantiating a new taskService, I had to pass in the constructor: username, accountDomain, password and forceV1 = true

 

worked for me ;)

Coordinator
Jul 4, 2010 at 4:27 PM

There was actually a bug in the Beta 2 release that caused this failure. Try the 1.5 Beta 3 code and remove the changes you made to the TaskService constructor.