【问题标题】:Create a WorkItem fails with "Object reference not set to an instance of an object."创建 WorkItem 失败,并显示“对象引用未设置为对象的实例”。
【发布时间】:2019-03-05 07:01:12
【问题描述】:

当使用以下参数创建工作项时,我们从 forge 中得到了一个内部错误:

{
  "error":{
    "code":"","message":"An error has occurred.","innererror":{
      "message":"Object reference not set to an instance of an object.","type":"System.NullReferenceException","stacktrace":"   at PublicApi.ResponseExceptionHelper.Throw(HttpStatusCode status, ModelStateDictionary state) in G:\\Repos\\IO\\src\\PublicAPI\\ResponseExceptionHelper.cs:line 31\r\n   at PublicApi.V2.Controllers.WorkItemsV2Controller.CreateEntity(WorkItem2 workItem) in G:\\Repos\\IO\\src\\PublicAPI\\V2\\Controllers\\WorkItemsV2Controller.cs:line 57\r\n   at PublicApi.V2.Controllers.BaseController`1.Post(TEntity entity) in G:\\Repos\\IO\\src\\PublicAPI\\V2\\Controllers\\BaseV2Controller.cs:line 62\r\n   at lambda_method(Closure , Object , Object[] )\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Tracing.ITraceWriterExtensions.<TraceBeginEndAsyncCore>d__18`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Tracing.ITraceWriterExtensions.<TraceBeginEndAsyncCore>d__18`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Tracing.Tracers.HttpControllerTracer.<ExecuteAsyncCore>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Tracing.ITraceWriterExtensions.<TraceBeginEndAsyncCore>d__18`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
    }
  }
}

以下 JSON 传递给 Forge 时会发生这种情况。 (部分数值与实际有所不同)

{
  "@odata.type": "#ACES.Models.WorkItem",
  "ActivityId": "CustomActivity",
  "Arguments": {
    "InputArguments": [
      {
        "HttpVerb": "GET",
        "Name": "HostDwg",
        "Resource": "https://s3.amazonaws.com/[path-redacted]",
        "ResourceKind": "ZipPackage",
        "StorageProvider": "Generic"
      },
      {
        "HttpVerb": "GET",
        "Name": "Request",
        "Resource": "https://s3.us-east-2.amazonaws.com/[path-redacted]",
        "ResourceKind": "ZipPackage",
        "StorageProvider": "Generic"
      }
    ],
    "OutputArguments": [
      {
        "HttpVerb": "POST",
        "Name": "GeneratedDrawing.dwg",
        "ResourceKind": "ZipPackage",
        "StorageProvider": "Generic"
      }
    ]
  },
  "Id": "",
  "UserID": "",
  "Version": 1
}

我已经对此代码尝试了多种变体。我已经添加了其他字段并包含了默认值......但是没有任何东西通过这个。

【问题讨论】:

  • 你能检查一下你的Activity是否真的有一个名为“GeneratedDrawing.dwg”的输出参数吗?此名称看起来像相应 Activity 参数的 LocalFileName。我怀疑输出参数的名称类似于“结果”,并且您的工作项的输出参数必须按参数名称匹配参数。
  • 这很好。我更改了名称 OutputArgument 以匹配“结果”。结果是示例代码中的正确名称。但是,我仍然遇到同样的错误。
  • 作为一个健全的检查,当我按照教程进行一些简单的事情(比如将 DWG 转换为 PDF)时,提交活动会给我一个 504 网关超时。这个 Forge API 帐户可能有问题吗?
  • 这是由于 ModelState 无效(您的请求正文对目标活动的参数方案无效,并且响应中的空指针错误实际上是我们的不良编码习惯但与问题的原因无关)。您确定输入和输出的所有名称和值都匹配吗?

标签: autodesk-forge autodesk-designautomation


【解决方案1】:

我看到的第一个问题是尾随逗号。这不是有效的 json。 InputArguments["HostDwg"] 和 OutputArguments["GeneratedDrawing.dwg"] 中的“Generic”之后不应有逗号。

【讨论】:

  • 感谢您的意见!我实际上已经删除了最后一个请求中包含的一些字段。我在StorageProviders 之后有一行"Authentication": null。我确保通过jsonlint.com 手动验证请求是有效的 json。即,如果您删除逗号,我仍然会收到相同的错误。
猜你喜欢
  • 1970-01-01
  • 2014-04-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多