Title: The powershell commandlet New-AzureRmWebAppSlot randomly gives a "'Location' cannot be null" error
Tags: azure-devops;azure-web-app-service;azure-pipelines;azure-powershell;azure-rm
Question: We have a PowerShell script that for each deployment creates a slot on each of the Azure web app that is involved in the deployment. This morning this suddenly started to fail for many of our deployments, but not all even it the same code was being run and deployed.

The line that started to fail:

```$deploySlot = New-AzureRmWebAppSlot -ResourceGroupName "$ResourceGroupName" -Name "$($webapp.serviceApp)" -Slot "$slotName"
```

I added ```Resolve-AzureRmError -Last``` in a try catch around the command and got the following:

```2018-10-17T06:35:06.0228046Z 
2018-10-17T06:35:06.0228769Z 
2018-10-17T06:35:06.0230563Z    HistoryId: 1
2018-10-17T06:35:06.0230703Z 
2018-10-17T06:35:06.0231161Z 
2018-10-17T06:35:06.0234999Z Message        : 'Location' cannot be null.
2018-10-17T06:35:06.0235402Z StackTrace     :    at Microsoft.Azure.Management.WebSites.Models.Resource.Validate()
2018-10-17T06:35:06.0235646Z                     at Microsoft.Azure.Management.WebSites.Models.Site.Validate()
2018-10-17T06:35:06.0268780Z                     at Microsoft.Azure.Management.WebSites.WebAppsOperations.<BeginCreateOrUpdateSlotWithHttpMessagesAs
2018-10-17T06:35:06.0269062Z                  ync&gt;d__326.MoveNext()
2018-10-17T06:35:06.0269217Z                  --- End of stack trace from previous location where exception was thrown ---
2018-10-17T06:35:06.0269503Z                     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2018-10-17T06:35:06.0269658Z                     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2018-10-17T06:35:06.0301248Z                     at Microsoft.Azure.Management.WebSites.WebAppsOperations.<CreateOrUpdateSlotWithHttpMessagesAsync&gt;d
2018-10-17T06:35:06.0302594Z                  __137.MoveNext()
2018-10-17T06:35:06.0304593Z                  --- End of stack trace from previous location where exception was thrown ---
2018-10-17T06:35:06.0306400Z                     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2018-10-17T06:35:06.0306724Z                     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2018-10-17T06:35:06.0312293Z                     at Microsoft.Azure.Management.WebSites.WebAppsOperationsExtensions.<CreateOrUpdateSlotAsync&gt;d__265.
2018-10-17T06:35:06.0314813Z                  MoveNext()
2018-10-17T06:35:06.0314990Z                  --- End of stack trace from previous location where exception was thrown ---
2018-10-17T06:35:06.0315157Z                     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2018-10-17T06:35:06.0315321Z                     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2018-10-17T06:35:06.0315562Z                     at Microsoft.Azure.Commands.WebApps.Utilities.WebsitesClient.CreateWebApp(String 
2018-10-17T06:35:06.0315722Z                  resourceGroupName, String webAppName, String slotName, String location, String serverFarmId, 
2018-10-17T06:35:06.0315886Z                  CloningInfo cloningInfo, String aseName, String aseResourceGroupName)
2018-10-17T06:35:06.0316053Z                     at 
2018-10-17T06:35:06.0316261Z                  Microsoft.Azure.Commands.WebApps.Cmdlets.DeploymentSlots.NewAzureWebAppSlotCmdlet.ExecuteCmdlet()
2018-10-17T06:35:06.0316608Z                     at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
2018-10-17T06:35:06.0316902Z Exception      : Microsoft.Rest.ValidationException
2018-10-17T06:35:06.0317067Z InvocationInfo : {New-AzureRmWebAppSlot}
2018-10-17T06:35:06.0323731Z Line           :                 $deploySlot = New-AzureRmWebAppSlot -ResourceGroupName "$ResourceGroupName" -Name 
2018-10-17T06:35:06.0324841Z                  "$($webapp.serviceApp)" -Slot "$slotName"  
2018-10-17T06:35:06.0325059Z                  
2018-10-17T06:35:06.0325200Z Position       : At D:\a\r1\a\Cloud apps\AzureDeploy\Publish-WebApps.ps1:313 char:31
2018-10-17T06:35:06.0326182Z                  + ... eploySlot = New-AzureRmWebAppSlot -ResourceGroupName "$ResourceGroupN ...
2018-10-17T06:35:06.0326820Z                  +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2018-10-17T06:35:06.0326981Z HistoryId      : 1
2018-10-17T06:35:06.0327103Z 
```

The command is executed on a VSTS Azure PowerShell task. 

I added a retry inside the try catch and it seems to always work for the retry.  Is something timing out?

Comment: Did you crossed slot limit ?

Comment: No. Running the same command inside the `catch section`  works fine as a workaround, so pretty sure that is not the case



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 0, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2018:00:10/17/18', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<azure-devops><azure-web-app-service><azure-pipelines><azure-powershell><azure-rm>', 'Title': 'The powershell commandlet New-AzureRmWebAppSlot randomly gives a "\'Location\' cannot be null" error', 'ViewCount': 124, 'id': 52851765, 'user_AboutMe': '<p>I worked previously with .NET technologies, but have now turned into the open source world.</p>\n', 'user_AccountId': 23267.0, 'user_DisplayName': 'Atle', 'user_Reputation': 436.0, 'user_Views': 100.0, 'user_id': 58170.0}}