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

Value does not fall within the expected range

Sep 17, 2010 at 1:56 PM

Getting following error when creating a tesk passing date in dtSTARTBOUNDARY. The same code is working fine in my dev. machine WINDOWS XP and its not working when deployed on WINDOWS 2003.

Thanks in advance

 NOuman

System.ArgumentException: Value does not fall within the expected range.
   at Microsoft.Win32.TaskScheduler.V1Interop.ITaskTrigger.SetTrigger(TaskTrigger& Trigger)
   at Microsoft.Win32.TaskScheduler.Trigger.SetV1TriggerData()
   at Microsoft.Win32.TaskScheduler.Trigger.set_StartBoundary(DateTime value)
   at MSR_SAP_RPSCore.clsTaskScheduler.AddTask(String strTaskName, String strTRIGGERTYPE, DateTime dtSTARTBOUNDARY, String strActionPath, String strTaskDesc, String strActionParam, String strActionWorkingdir)

 

 

Public Function AddTask(ByVal strTaskName As String, ByVal strTRIGGERTYPE As String, ByVal dtSTARTBOUNDARY As Date, ByVal strActionPath As String, Optional ByVal strTaskDesc As String = "", Optional ByVal strActionParam As String = "", Optional ByVal strActionWorkingdir As String = Nothing) As Boolean

 

 Dim objtd As TaskDefinition = Nothing

 Dim objtask As Task = Nothing

 Dim blnSuccess As Boolean = False

 Try

objtd = objTaskService.NewTask()

 If objtd Is Nothing AndAlso strScheduleTaskLoginID.Length > 0 AndAlso strScheduleTaskLoginPassword.Length > 0 Then

 'retry with login with provided credentails

objTaskService =New TaskService(strScheduleTaskComputer, strScheduleTaskLoginID, strScheduleTaskDomain, strScheduleTaskLoginPassword)

objtd = objTaskService.NewTask()

 End If

 

If objtd IsNot Nothing Then

 If strActionPath.Length = 0 Then

strActionPath = strScheduleApplication

 End If

objtd.RegistrationInfo.Description = strTaskDesc

objtd.Principal.LogonType = TaskLogonType.ServiceAccount

' TaskLogonType.InteractiveToken

objtd.Principal.UserId = m_strUserIDToRegisterTask

 Select Case strTRIGGERTYPE

 Case Is = "Daily" 'every day

 Dim dt As DailyTrigger = objtd.Triggers.Add(New DailyTrigger())

dt.StartBoundary = dtSTARTBOUNDARY

 Case Is = "Weekly" 'every monday

 Dim dt As WeeklyTrigger = objtd.Triggers.Add(New WeeklyTrigger())

dt.StartBoundary = dtSTARTBOUNDARY

dt.DaysOfWeek = DaysOfTheWeek.Monday

 Case Is = "Monthly"

 Dim dt As MonthlyTrigger = objtd.Triggers.Add(New MonthlyTrigger())

dt.StartBoundary = dtSTARTBOUNDARY

 Case Is = "Once"

 Dim dt As TimeTrigger = objtd.Triggers.Add(New TimeTrigger())

dt.StartBoundary = dtSTARTBOUNDARY

 End Select

 

objtd.Actions.Add(New ExecAction(strActionPath, strActionParam, strActionWorkingdir))

 

'Register the task in the root folder

 If strScheduleTaskLoginID.Length > 0 AndAlso strScheduleTaskLoginPassword.Length > 0 Then

objTaskService.RootFolder.RegisterTaskDefinition(strTaskName, objtd, TaskCreation.Create, strScheduleTaskLoginID, strScheduleTaskLoginPassword, TaskLogonType.Password,Nothing)

 Else

objTaskService.RootFolder.RegisterTaskDefinition(strTaskName, objtd, TaskCreation.Create,Nothing, Nothing, TaskLogonType.ServiceAccount, Nothing)

 End If

blnSuccess =True

 Else

_Error =

"Task retrieval failed"

blnSuccess =False

 End If

 Catch ex As Exception

blnSuccess =False

_Error = ex.ToString

 End Try

 Return blnSuccess

 End Function

 

 

Coordinator
Sep 19, 2010 at 2:19 AM

The only thing that can be causing the failure you are having is if the dtSTARTBOUNDARY values for year, month or day are not valid. Some validation may help.

Sep 20, 2010 at 12:27 PM
dahall wrote:

The only thing that can be causing the failure you are having is if the dtSTARTBOUNDARY values for year, month or day are not valid. Some validation may help.

 Thanks for the reply but I am passing valid date time from datetimepicker control (.net) . The strange thing is that the same code work on my machine windwos xp but it didn't work when deployed on windows 2003.What is the date format you passed , my date also has time in it for e.g date is being passed like this #9/20/2010 8:25:26 AM#

Can it cause the issue? should I remove the time part?

Thanks

Nouman

Sep 20, 2010 at 5:16 PM

I got it working it was issue with Regional settings on the windows 2003 server and date time was not passed correctly to the trigger.

Thanks

Nouman