簡體   English   中英

Azure 函數 - New-AzContainerGroup:未將對象引用設置為對象的實例

[英]Azure Functions - New-AzContainerGroup : Object reference not set to an instance of an object

我一直在嘗試使用 http 觸發的 powershell Azure 函數創建 Azure 容器實例。

我寫了一些代碼並且它有效......有點

using namespace System.Net

param($Request, $TriggerMetadata)

$appId = "appID"
$appPassword = "appPassword"
$secpasswd = ConvertTo-SecureString $appPassword -AsPlainText -Force
$mycred = New-Object System.Management.Automation.PSCredential ($appId, $secpasswd)

$status = [HttpStatusCode]::OK
New-AzContainerGroup -ResourceGroupName "test" -Name "testName" `
    -Image "imageName" `
    -RegistryCredential $mycred `
    -RestartPolicy Never

Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
    StatusCode = $status
    Body = $body
})

當我點擊端點時,我總是得到 500 響應代碼,但由於某種原因容器實例正在被創建並且它可以工作。 這是來自終端的錯誤:

Executed 'Functions.testFuntion' (Failed, Id=240084c5-6aa2-4207-ae84-66f85a03504b)
System.Private.CoreLib: Exception while executing function: Functions.testFuntion. 
System.Private.CoreLib: Result: Failure
Exception: Object reference not set to an instance of an object.
Stack: 
at 
Microsoft.Azure.Functions.PowerShellWorker.Utility.TypeExtensions.
DeriveContentType(HttpResponseContext  
Microsoft.Azure.Functions.PowerShellWorker.Utility.TypeExtensions.DeriveContentType
(HttpResponseContext httpResponseContext, RpcHttp rpcHttp) in C:\projects\azure-functions-powershell- 
worker\src\Utility\TypeExtensions.cs:line 196
at 
Microsoft.Azure.Functions.PowerShellWorker.Utility.TypeExtensions.ToRpcHttp(HttpResponseContext 
httpResponseContext) in C:\projects\azure-functions-powershell- 
worker\src\Utility\TypeExtensions.cs:line 188
at 
Microsoft.Azure.Functions.PowerShellWorker.Utility.TypeExtensions.ToTypedData(Object value) in 
C:\projects\azure-functions-powershell-worker\src\Utility\TypeExtensions.cs:line 242
at 
Microsoft.Azure.Functions.PowerShellWorker.RequestProcessor.BindOutputFromResult(InvocationResponse 
response, AzFunctionInfo functionInfo, Hashtable results) in C:\projects\azure-functions-powershell- 
worker\src\RequestProcessor.cs:line 465
at
Microsoft.Azure.Functions.PowerShellWorker.RequestProcessor.ProcessInvocationRequestImpl
(StreamingMessage request, AzFunctionInfo functionInfo, PowerShellManager psManager,
FunctionInvocationPerformanceStopwatch stopwatch)
in C:\projects\azure-functions-powershell-worker\src\RequestProcessor.cs:line 305.

這是我應該擔心的事情嗎? 盡管我收到了 500 條回復,但似乎一切正常。

您可能需要先定義 $body,然后才能在 Push-OutputBinding 響應中使用它。

就像是:

$body = "My Message"
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
    StatusCode = $status
    Body = $body
})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM