This project has moved. For the latest updates, please go here.

Unhandled Exception in Wizard

Jan 12, 2012 at 8:33 PM
Edited Jan 12, 2012 at 8:33 PM

I just tried the TaskSchedulerWizard:

 

using (TaskSchedulerWizard wiz = new TaskSchedulerWizard())
{
  wiz.ShowDialog();
}

 

In the Security OPtions step, no matter what I try (clicking on the "Change User or Group", "Run only..." etc, it crashes with:

 

System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Win32.TaskScheduler.TaskSchedulerWizard.taskLocalOnlyCheck_CheckedChanged(Object sender, EventArgs e)
   at Microsoft.Win32.TaskScheduler.TaskSchedulerWizard.taskLoggedOptionalRadio_CheckedChanged(Object sender, EventArgs e)
   at System.Windows.Forms.RadioButton.OnCheckedChanged(EventArgs e)
   at System.Windows.Forms.RadioButton.set_Checked(Boolean value)
   at System.Windows.Forms.RadioButton.OnClick(EventArgs e)
   at System.Windows.Forms.RadioButton.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.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Any ideas?

Coordinator
Jan 12, 2012 at 9:53 PM

You must initialize the dialog by calling the Initialize method before calling ShowDialog.

Jan 12, 2012 at 10:13 PM
Edited Jan 12, 2012 at 10:24 PM

Ah, ok. Sorry.

But how do I save the new task?

 

using (TaskService ts = new TaskService())
{
  using (TaskSchedulerWizard wiz = new TaskSchedulerWizard())
  {
    TaskDefinition newTaskDef = ts.NewTask();
    wiz.Initialize(ts, newTaskDef);

    if (wiz.ShowDialog() == DialogResult.OK)
    {
      // save task
      ts.RootFolder.RegisterTaskDefinition(newTaskDef.Data, newTaskDef);

    }
  }
}

 

EDIT: Ah, figured it out.

Simply use: 

ts.RootFolder.RegisterTaskDefinition(newTaskDef.Data, newTaskDef);
Coordinator
Jan 12, 2012 at 11:37 PM
Edited Jan 12, 2012 at 11:39 PM


Alternately, you can also use the following and the wizard will do the work for you:

using (TaskService ts = new TaskService())
{
  TaskSchedulerWizard wiz = new TaskSchedulerWizard();
  wiz.Initialize(ts);
  wiz.RegisterTaskOnFinish = true;
  wiz.ShowDialog();
}
Jun 14, 2012 at 6:00 AM

Hi dahall, I'm having the same problem and seems the posted code doesn't work.

Here is my code using taskscheduler-78172 running on Windows XP Professional 2002 SP3.

            using(TaskService ts = new TaskService())
            {
                TaskDefinition td = ts.NewTask();
                TaskSchedulerWizard wizard = new TaskSchedulerWizard();
                wizard.Initialize(ts, td);
                wizard.RegisterTaskOnFinish = true;
                wizard.ShowDialog();
            }

When I come to Security Options page, user account is automatically displayed, and I click Next button, popup dialog shows to input user name and password.

After I input them, I got this exception:

System.NullReferenceException was unhandled
  Message="Object reference not set to an instance of an object."
  Source="Microsoft.Win32.TaskSchedulerEditor"
  StackTrace:
       at Microsoft.Win32.TaskScheduler.CredentialsDialog.IsValidPassword(String userName, String password)
       at Microsoft.Win32.TaskScheduler.CredentialsDialog.RunDialog(IntPtr parentWindowHandle)
       at System.Windows.Forms.CommonDialog.ShowDialog(IWin32Window owner)
       at Microsoft.Win32.TaskScheduler.TaskSchedulerWizard.InvokeCredentialDialog(String userName)
       at Microsoft.Win32.TaskScheduler.TaskSchedulerWizard.secOptPage_Commit(Object sender, WizardPageConfirmEventArgs e)
       at AeroWizard.WizardPage.OnCommit()
       at AeroWizard.WizardPage.CommitPage()
       at AeroWizard.WizardControl.NextPage(WizardPage nextPage)
       at AeroWizard.WizardControl.NextPage()
       at AeroWizard.WizardControl.nextButton_Click(Object sender, EventArgs e)
       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.RunDialog(Form form)
       at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
       at System.Windows.Forms.Form.ShowDialog()
       at DataUploadAutomationTest.TaskScheduler.OpenWizard() in C:\Source\DataUploadAutomationTest\DataUploadAutomationTest\TaskScheduler.cs:line 28
       at DataUploadAutomationTest.TaskScheduler.Main(String[] args) in C:\Source\DataUploadAutomationTest\DataUploadAutomationTest\TaskScheduler.cs:line 15
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       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:

Any idea?

Coordinator
Jun 15, 2012 at 4:04 AM

I don't know for sure if this will work, but try setting the td.Principal.UserId to a real value before initializing the wizard.

Jun 15, 2012 at 7:48 AM

Hey dahall, thanks a lot! It solved the problem.

 

Seems like it's a bug in "CredentialsDialog.RunDialog" method, in the following line -

......

if (this.ValidatePassword && !IsValidPassword(this.UserName, password.ToString()))

......

Instead of using "this.UserName", it should just use "userName" cause that one is filled after calling "CredUIPromptForCredentials" method, right?