Azure Functions-新-AzContainerGroup : Object reference not set to an instance of an object

标签 azure powershell azure-functions azure-container-instances

我一直在尝试使用 http 触发的 powershell Azure Function 创建 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 条回复,但一切似乎都正常。

最佳答案

在 Push-OutputBinding 响应中使用 $body 之前,您可能需要定义它。

类似于:

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

关于Azure Functions-新-AzContainerGroup : Object reference not set to an instance of an object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60977663/

相关文章:

python - 用于本地脚本的 Azure 函数 "ModuleNotFoundError"

windows-phone-7 - Azure 队列 Windows Phone

sql-server - Azure 是否有适用于 Ms SQL DB 的 REST API 服务/包装器?

powershell - 如何增加 VM 上的并发 PowerShell 实例数?

Powershell IE 自动化 FireEvent 未触发

powershell - 如何使用从 Powershell 中选择的文件调用 Windows 资源管理器?

Azure Function 中的 Azure 服务总线处理程序

azure-functions - 宇宙数据库 : The request failed because the client was unable to establish connections to 1 endpoints across 1 regions

Azure 函数队列触发器的 Azure 存储模拟器连接字符串

c# - 在 Windows Azure 上运行 Fleck(或任何)Websocket 服务器