Azure / Azure/azure-powershell
Get-AzAutomationRunbook returns Object reference not set to an instance of an object error
- Dominant language
- C#
- Stars
- 4.8k
- Forks
- 4.3k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 51
Description
### Description
Running `Get-AzAutomationRunbook` commands gives Object reference not set exception. I have verified the parameters that are being passed are valid.
### Issue script & Debug output
```PowerShell
PS C:\Users\MadhuRaju> Get-AzAutomationRunbook -ResourceGroupName 'dev-rg-ng-infra-shared-eau' -AutomationAccountName 'dev-aa-ng-infra' -Name 'Retire-Container-App'
DEBUG: Initializing ConditionalAssemblyContext. PSEdition is [Desktop]. PSVersion is [5.1.22621.2506].
DEBUG: Initializing ConditionalAssemblyProvider. AssemblyRootPath is [C:\Program
Files\WindowsPowerShell\Modules\Az.Accounts\3.0.0\StartupScripts\..\lib].
DEBUG: Got version 0 of Az
DEBUG: Got version 0 of Az.Accounts
DEBUG: 1:59:58 PM - [ConfigManager] Got nothing from [DisplaySecretsWarning], Module = [], Cmdlet = []. Returning
default value [True].
DEBUG: 1:59:58 PM - GetAzureAutomationRunbook begin processing with ParameterSet 'ByRunbookName'.
DEBUG: 1:59:58 PM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning
default value [True].
DEBUG: 1:59:58 PM - [ConfigManager] Got nothing from [EnableErrorRecordsPersistence], Module = [], Cmdlet = [].
Returning default value [False].
Get-AzAutomationRunbook : Object reference not set to an instance of an object.
At line:1 char:1
+ Get-AzAutomationRunbook -ResourceGroupName 'dev-rg-ng-infra-shared-ea ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Get-AzAutomationRunbook], NullReferenceException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Automation.Cmdlet.GetAzureAutomationRunbook
DEBUG: 1:59:58 PM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning
default value [True].
DEBUG: 1:59:58 PM - [ConfigManager] Got nothing from [DisplayRegionIdentified], Module = [], Cmdlet = []. Returning
default value [True].
DEBUG: 1:59:58 PM - [ConfigManager] Got nothing from [CheckForUpgrade], Module = [], Cmdlet = []. Returning default
value [True].
DEBUG: AzureQoSEvent: Module: Az.Automation:1.10.0; CommandName: Get-AzAutomationRunbook; PSVersion: 5.1.22621.2506;
IsSuccess: False; Duration: 00:00:00.2175639; SanitizeDuration: 00:00:00; Exception: Object reference not set to an
instance of an object.;
DEBUG: 1:59:58 PM - [ConfigManager] Got nothing from [EnableDataCollection], Module = [], Cmdlet = []. Returning default
value [True].
DEBUG: 1:59:58 PM - GetAzureAutomationRunbook end processing.
```
### Environment data
```PowerShell
Name Value
---- -----
PSVersion 5.1.22621.2506
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.22621.2506
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
```
### Module versions
```PowerShell
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 3.0.0 Az.Accounts {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-...
Script 1.10.0 Az.Automation {Export-AzAutomationDscConfiguration, Export-AzAutomationDs...
```
### Error output
```PowerShell
DEBUG: 2:05:41 PM - [ConfigManager] Got nothing from [DisplaySecretsWarning], Module = [], Cmdlet = []. Returning
default value [True].
DEBUG: 2:05:41 PM - ResolveError begin processing with ParameterSet 'AnyErrorParameterSet'.
DEBUG: 2:05:41 PM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning
default value [True].
DEBUG: 2:05:41 PM - [ConfigManager] Got nothing from [DisplaySecretsWarning], Module = [], Cmdlet = []. Returning
default value [True].
HistoryId: 2
Message : Object reference not set to an instance of an object.
StackTrace : at Microsoft.Azure.Commands.Automation.Common.AutomationPSClient..ctor(IAzureContext context)
at Microsoft.Azure.Commands.Automation.Cmdlet.AzureAutomationBaseCmdlet.get_AutomationClient()
at Microsoft.Azure.Commands.Automation.Cmdlet.GetAzureAutomationRunbook.AutomationProcessRecord()
at Microsoft.Azure.Commands.Automation.Cmdlet.AzureAutomationBaseCmdlet.ExecuteCmdlet()
at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
Exception : System.NullReferenceException
InvocationInfo : {Get-AzAutomationRunbook}
Line : Get-AzAutomationRunbook -ResourceGroupName 'dev-rg-ng-infra-shared-eau' -AutomationAccountName
'dev-aa-ng-infra' -Name 'Retire-Container-App'
Position : At line:1 char:1
+ Get-AzAutomationRunbook -ResourceGroupName 'dev-rg-ng-infra-shared-ea ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 2
DEBUG: 2:05:41 PM - [ConfigManager] Got nothing from [DisplayRegionIdentified], Module = [], Cmdlet = []. Returning
default value [True].
DEBUG: 2:05:41 PM - [ConfigManager] Got nothing from [CheckForUpgrade], Module = [], Cmdlet = []. Returning default
value [True].
DEBUG: AzureQoSEvent: Module: Az.Accounts:3.0.0; CommandName: Resolve-AzError; PSVersion: 5.1.22621.2506; IsSuccess:
True; Duration: 00:00:00.1091753; SanitizeDuration: 00:00:00.0127862
DEBUG: 2:05:41 PM - [ConfigManager] Got nothing from [EnableDataCollection], Module = [], Cmdlet = []. Returning default
value [True].
DEBUG: 2:05:41 PM - ResolveError end processing.
```
Contributor guide
Research direction
Reproduce Get-AzAutomationRunbook with the reported parameters and module versions, then trace the stack from GetAzureAutomationRunbook.AutomationProcessRecord through AzureAutomationBaseCmdlet.get_AutomationClient to AutomationPSClient..ctor. Done means valid parameters return the runbook without a NullReferenceException and the failure is covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, powershell
- Domain
- backend, cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 38/100