3

I'm writing a small web interface which goes on the front of a System Center Orchestrator setup. It is supposed to hit the runbook and get some data back - this part is largely unimportant.

The code is attempting to start a runbook job to get some data back using the sample code (and subbing in my requirements) from https://msdn.microsoft.com/en-us/library/hh921685.aspx

The only lines I have changed are the references to my own Orchestrator, the runbook GUID, and the runbook parameters.

This line throws the exception in the title:

context.SaveChanges();

which has this stack trace showing the error seems to be originating somewhere in the OData realm of things which is well beyond my code:

[ArgumentOutOfRangeException: The UTC time represented when the offset is applied must be between year 0 and 10,000.
Parameter name: offset]
   System.DateTimeOffset.ValidateDate(DateTime dateTime, TimeSpan offset) +14215620
   System.DateTimeOffset..ctor(DateTime dateTime) +56
   Microsoft.Data.OData.Atom.EpmSyndicationWriter.CreateDateTimeStringValue(Object propertyValue, ODataWriterBehavior writerBehavior) +144
   Microsoft.Data.OData.Atom.EpmSyndicationWriter.WriteEntryEpm(EntryPropertiesValueCache epmValueCache, IEdmEntityTypeReference entityType) +652
   Microsoft.Data.OData.Atom.EpmSyndicationWriter.WriteEntryEpm(EpmTargetTree epmTargetTree, EntryPropertiesValueCache epmValueCache, IEdmEntityTypeReference type, ODataAtomOutputContext atomOutputContext) +80
   Microsoft.Data.OData.Atom.ODataAtomWriter.EndEntry(ODataEntry entry) +627
   Microsoft.Data.OData.ODataWriterCore.<WriteEndImplementation>b__16() +168
   Microsoft.Data.OData.ODataWriterCore.InterceptException(Action action) +121
   Microsoft.Data.OData.ODataWriterCore.WriteEndImplementation() +69
   Microsoft.Data.OData.ODataWriterCore.WriteEnd() +40
   System.Data.Services.Client.ODataWriterWrapper.WriteEnd(ODataEntry entry, Object entity) +47
   System.Data.Services.Client.Serializer.WriteEntry(EntityDescriptor entityDescriptor, IEnumerable`1 relatedLinks, ODataRequestMessageWrapper requestMessage) +485
   System.Data.Services.Client.BaseSaveResult.CreateRequestData(EntityDescriptor entityDescriptor, ODataRequestMessageWrapper requestMessage) +117
   System.Data.Services.Client.BaseSaveResult.CreateChangeData(Int32 index, ODataRequestMessageWrapper requestMessage) +136
   System.Data.Services.Client.SaveResult.CreateNonBatchChangeData(Int32 index, ODataRequestMessageWrapper requestMessage) +224
   System.Data.Services.Client.SaveResult.CreateNextChange() +174
   System.Data.Services.Client.DataServiceContext.SaveChanges(SaveChangesOptions options) +178
   System.Data.Services.Client.DataServiceContext.SaveChanges() +37
   S3Tools.RunbookOperations.GetClusters(String site) in [redacted]\RunbookOps.cs:58

I have looked at The UTC time represented when the offset is applied must be between year 0 and 10,000. Parameter name: offset and UTC time represented when the offset is applied must be between year 0 and 10,000 error and it looks suspiciously like that error (especially the latter) which calls on https://support.microsoft.com/en-us/kb/2346777 but the hotfix provided by MS doesn't apply to Windows 10 (my workstation) or Windows 2012 R2 (the webserver).

I am reluctant to change either my timezone (UTC+10) or the server's to test before seeing if anyone has any ideas or has encountered this before.

I have powershell scripts which are quite capable of generating these jobs (although they can't use service references you have to generate the request manually). So I'm not inclined to believe anything is at fault except the CLR.

Bottom line question: Has anyone encountered this and fixed it?

Community
  • 1
  • 1
Kruft
  • 273
  • 3
  • 13
  • This morning I decided to try changing my workstation's timezones to see if this made any difference. It didn't. I tried both UTC and UTC-12. So I don't think it's a result of this. – Kruft Apr 19 '16 at 22:03
  • I've just seen [this technet article](https://social.technet.microsoft.com/Forums/en-US/e248ecef-9561-4409-8a3f-8299bcc721a4/exception-using-code-sample-in-utc-1-timezone?forum=scoqik) which may work. Giving it a whirl. – Kruft Apr 19 '16 at 22:06

1 Answers1

1

Adding these two lines will alleviate the issue:

job.CreationTime = DateTime.Now;
job.LastModifiedTime = DateTime.Now;

Or, of course, to any reasonably valid DateTime value.

So it seems to be that when using the sample code referred to in the question that the empty Job object doesn't populate the CreationTime or LastModifiedTime properties, and as a result it passes that through. When the times get used in a calculation they result in a timespan which is < 0 or > 10,000 years.

The solution was in this technet forum thread: https://social.technet.microsoft.com/Forums/en-US/e248ecef-9561-4409-8a3f-8299bcc721a4/exception-using-code-sample-in-utc-1-timezone?forum=scoqik

with the answer by JoakimJohansson.

Kruft
  • 273
  • 3
  • 13