【问题标题】:REST API to Entity "Bill" throwing a 500 System.NullReferenceExceptionREST API 到实体“Bill”抛出 500 System.NullReferenceException
【发布时间】:2021-04-05 16:24:42
【问题描述】:

我有一个使用 REST API 为项目任务创建两个账单的流程。特定供应商类别的供应商的第一张账单总是成功创建并且可以正常处理。不同供应商类别的供应商的第二张账单几乎总是失败,引发 500 Internal Server 错误。它们都将相同的数据结构传递给相同的函数来创建账单,我已经比较了从结构中编组并传递给 API 的 JSON。它在结构上是相同的——只是值不同。这是我收到错误时的响应正文:

{
    "message": "An error has occurred.",
    "exceptionMessage": "Object reference not set to an instance of an object.",
    "exceptionType": "System.NullReferenceException",
    "stackTrace": "   at PX.Api.ContractBased.SystemContracts.V2.RestController.PutEntity(EntityImpl entity, String select, String filter, String expand, String custom)\r\n   at lambda_method(Closure , Object , Object[] )\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass6_1.<GetExecutor>b__3(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.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__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.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.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.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.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.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>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.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.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.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.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.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>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.Controllers.ActionFilterResult.<ExecuteAsync>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.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__3.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.ExceptionFilterResult.<ExecuteAsync>d__6.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.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__6.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__15.MoveNext()"
}

我正在记录传递给 API 调用的 JSON。奇怪的是,如果我通过 Postman 发送相同的 JSON,它就可以工作。

这是我传递的 JSON。

{
    "note": "Bill for Job Assignment",
    "Amount": {
        "value": 210
    },
    "Date": {
        "value": "2020-12-28"
    },
    "DueDate": {
        "value": "2021-01-27"
    },
    "Hold": {
        "value": "false"
    },
    "LocationID": {
        "value": "MAIN"
    },
    "Terms": {
        "value": "SCHEDULE"
    },
    "Type": {
        "value": "Bill"
    },
    "Vendor": {
        "value": "V003700"
    },
    "VendorRef": {
        "value": "FC02000029"
    },
    "Details": [
        {
            "Branch": {
                "value": "EDS"
            },
            "InventoryId": {
                "value": "FEEFORSERVICE"
            },
            "Project": {
                "value": "V000026C000166"
            },
            "ProjectTask": {
                "value": "020000961900029"
            },
            "Qty": {
                "value": 6
            },
            "UnitCost": {
                "value": 35
            }
        }
    ],
    "custom": {
        "Document": {
            "AttributeDETAILLOC": {
                "type": "CustomStringField",
                "value": "1240 Jones Mill Rd"
            },
            "AttributeENDTIME": {
                "type": "CustomStringField",
                "value": "00:00"
            },
            "AttributeJOBDATE": {
                "type": "CustomDateTimeField",
                "value": "12/27/2020"
            },
            "AttributeJOBNBR": {
                "type": "CustomStringField",
                "value": 9619
            },
            "AttributeOFIDNBR": {
                "type": "CustomStringField",
                "value": "937"
            },
            "AttributeOFCREMPNBR": {
                "type": "CustomStringField",
                "value": "280"
            },
            "AttributeVENDORID": {
                "type": "CustomStringField",
                "value": "V003700"
            },
            "AttributeEMPNAME": {
                "type": "CustomStringField",
                "value": "Jones, James Earl"
            },
            "AttributeSTARTTIME": {
                "type": "CustomStringField",
                "value": "18:00"
            }
        }
    }
}

我希望堆栈跟踪中的线索对比我更熟悉 Acumatica REST API 的人来说意味着什么。

【问题讨论】:

  • 这两个供应商类别是否有可能需要一组不同的属性?其中之一是必需的?因此是空引用?只是一个想法。

标签: api rest acumatica http-status-code-500


【解决方案1】:

我能够解决问题。事实证明,这个问题与我正在创建的账单相关的项目任务状态的一些(秘密)变化有关。一旦我发布了一份账单,我就无法创建或发布另一份账单。在发布第二个帐单之前,我在中间添加了一个步骤,将项目任务的状态更改为“活动”(添加第一个帐单之前的状态),并且它起作用了。

另一个使用 REST API 的未记录要求。这涉及到大量的猜测,但是一旦你弄清楚了,它就会很好用!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-27
    • 1970-01-01
    • 2013-08-12
    • 1970-01-01
    • 1970-01-01
    • 2022-01-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多