0
votes

I'm trying to execute below command in a PowerShell Workflow Runbook. I'm getting the error "cannot index into a null array.", which is not true as the same script which ran perfectly on my local machine is not executing while in the Azure portal as a PowerShell Workflow Runbook.

Can anyone please look into this?

$webApp = Get-AzureRMWebAppSlot -ResourceGroupName $ResourceGroupName -Name $WebSiteName -Slot $WebSiteSlot
$webApp
"Printing Website ConncectionString"
$webApp.SiteConfig.ConnectionStrings.ConnectionString[0]

enter image description here

1
can you confirm that $webapp actually has data in it and is not $null? - 4c74356b41
Yes, I Updated the question to account for that. @4c74356b41 - NikhilGoud
Please note that I'm getting this issue specifically while executing this script as a workflow. if I run the same script without a workflow everything is just working fine. But I need workflow to mention params to the script and schedule the execution. - NikhilGoud

1 Answers

1
votes

Some types do not serialize/deserialize correctly, and in PowerShell Workflow that is a problem because PowerShell Workflow relies on object serialization/deserialization (that's how PSWF is able to checkpoint, suspend, and resume -- it converts all objects to a string form when checkpointing/suspending, and restores back to full objects from those strings when resuming).

It would appear Get-AzureRMWebAppSlot's output object is one of those types that does not serialize/deserialize correctly. From your screenshot I can see that the SiteConfig property of $webApp is a string containing Microsoft.Azure.Management.WebSites.Model.SiteConfig rather than an object as you're expecting. Clearly, the object is not deserializing correctly back to its original form, where SiteConfig is a complex object.

The way to work around this is to only interact with the object in PowerShell script context, rather than workflow context. For example:

workflow foo {
   $ResourceGroupName = "RG"
   $WebSiteName = "WS"
   $WebSiteSlot = "Slot"

   $ConnectionString = InlineScript {
      $webApp = Get-AzureRMWebAppSlot -ResourceGroupName $using:ResourceGroupName -Name $using:WebSiteName -Slot $using:WebSiteSlot
      $webApp.SiteConfig.ConnectionStrings.ConnectionString[0]
   }

   "Printing Website ConnectionString"
   $ConnectionString
}