【问题标题】:ArgumentOutOfRangeException (The UTC time represented when the offset is applied must be between year 0 and 10,000.) with OData / SC OrchestratorArgumentOutOfRangeException(应用偏移时表示的 UTC 时间必须介于 0 年和 10,000 年之间。)使用 OData / SC Orchestrator
【发布时间】:2016-04-19 04:50:32
【问题描述】:

我正在编写一个位于 System Center Orchestrator 设置前面的小型 Web 界面。它应该按运行手册获取一些数据 - 这部分基本上不重要。

该代码正在尝试使用来自https://msdn.microsoft.com/en-us/library/hh921685.aspx 的示例代码(并根据我的要求)来启动一个运行手册作业以获取一些数据

我更改的唯一行是对我自己的 Orchestrator、Runbook GUID 和 Runbook 参数的引用。

这行抛出了标题中的异常:

context.SaveChanges();

此堆栈跟踪显示错误似乎源自 OData 领域的某处,这远远超出了我的代码:

[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

我查看了The UTC time represented when the offset is applied must be between year 0 and 10,000. Parameter name: offsetUTC time represented when the offset is applied must be between year 0 and 10,000 error,它看起来很像调用https://support.microsoft.com/en-us/kb/2346777 的错误(尤其是后者),但 MS 提供的修补程序不适用于 Windows 10(我的工作站)或Windows 2012 R2(网络服务器)。

我不愿意更改我的时区 (UTC+10) 或服务器的时区,以便在查看是否有人有任何想法或以前遇到过这种情况之前进行测试。

我有 powershell 脚本,它们非常有能力生成这些作业(尽管它们不能使用您必须手动生成请求的服务引用)。所以我不倾向于相信除了 CLR 有任何问题。

底线问题:有人遇到过这个问题并解决了吗?

【问题讨论】:

  • 今天早上我决定尝试更改我的工作站的时区,看看这是否有什么不同。它没有。我尝试了 UTC 和 UTC-12。所以我认为这不是结果。
  • 我刚刚看到this technet article 可能有用。试一试。

标签: c#


【解决方案1】:

添加这两行将缓解该问题:

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

或者,当然,任何合理有效的 DateTime 值。

因此,似乎在使用问题中提到的示例代码时,空的 Job 对象不会填充 CreationTime 或 LastModifiedTime 属性,因此它会通过它。当在计算中使用时间时,它们会产生 10,000 年的时间跨度。

解决方案在这个 technet 论坛帖子中:https://social.technet.microsoft.com/Forums/en-US/e248ecef-9561-4409-8a3f-8299bcc721a4/exception-using-code-sample-in-utc-1-timezone?forum=scoqik

JoakimJohansson 的回答。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-27
    • 1970-01-01
    • 2015-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多