Azure / Azure/azure-powershell
Get-AzReservationOrderId throws NullReferenceException
- Dominant language
- C#
- Stars
- 4.8k
- Forks
- 4.3k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 51
Description
### Description
There is a situation that `Microsoft.Capacity/appliedReservations` returns `{"value": []}`. In such case, an NullReferenceException occurs at [the constructor of PSAppliedReservationOrderId](https://github.com/Azure/azure-powershell/blob/4668bff1cc4ed6510d9b0d4c6ec289ab27f04241/src/Reservations/Reservations/Custom/PSAppliedReservationOrderId.cs#L44) because appliedReservationOrder.ReservationOrderIds will be null.
```
(6a14.36b8): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
Microsoft_Azure_PowerShell_Cmdlets_Reservations!Microsoft.Azure.Commands.Reservations.Models.PSAppliedReservationOrderId..ctor(Microsoft.Azure.Management.Reservations.Models.AppliedReservations)+0x92:
00007ff9`efde68e2 3909 cmp dword ptr [rcx],ecx ds:00000000`00000000=????????
0:009> k
# Child-SP RetAddr Call Site
00 00000024`f840e4e0 00007ff9`efde1a67 Microsoft_Azure_PowerShell_Cmdlets_Reservations!Microsoft.Azure.Commands.Reservations.Models.PSAppliedReservationOrderId..ctor(Microsoft.Azure.Management.Reservations.Models.AppliedReservations)+0x92
01 00000024`f840e530 00007ff9`eede8414 Microsoft_Azure_PowerShell_Cmdlets_Reservations!Microsoft.Azure.Commands.Reservations.Cmdlets.GetReservationOrderId.ExecuteCmdlet()+0xd7
...
0:009> !DumpObj /d 0000019d58669f28
Name: Microsoft.Azure.Management.Reservations.Models.AppliedReservations
MethodTable: 00007ff9effeb8e0
EEClass: 00007ff9f0013650
Size: 48(0x30) bytes
File: C:\Users\hiroyha\Documents\PowerShell\Modules\Az.Reservations\0.9.0\Microsoft.Azure.Management.Reservations.dll
Fields:
MT Field Offset Type VT Attr Value Name
00007ff9ede37a90 4000019 8 System.String 0 instance 0000000000000000 k__BackingField
00007ff9ede37a90 400001a 10 System.String 0 instance 0000000000000000 k__BackingField
00007ff9ede37a90 400001b 18 System.String 0 instance 0000000000000000 k__BackingField
00007ff9f00203b0 400001c 20 ...edReservationList 0 instance 0000000000000000 k__BackingField
```
### Issue script & Debug output
```PowerShell
PS> Get-AzReservationOrderId -SubscriptionId XXXX -debug
...
DEBUG: ============================ HTTP RESPONSE ============================
Status Code:
OK
Headers:
Cache-Control : no-cache
Pragma : no-cache
x-ms-request-id : 3b5b6987-1ae4-4041-b275-3ac99638a0d0
x-ms-correlation-request-id : 3b5b6987-1ae4-4041-b275-3ac99638a0d0
x-ms-routing-request-id : JAPANWEST:20211127T135123Z:3b5b6987-1ae4-4041-b275-3ac99638a0d0
Strict-Transport-Security : max-age=31536000; includeSubDomains
X-Content-Type-Options : nosniff
Date : Sat, 27 Nov 2021 13:51:23 GMT
Body:
{
"value": []
}
Get-AzReservationOrderId: Object reference not set to an instance of an object.
DEBUG: AzureQoSEvent: Module: Az.Reservations:0.9.0; CommandName: Get-AzReservationOrderId; PSVersion: 7.1.2; IsSuccess: False; Duration: 00:00:00.9515935; Exception: Object reference not set to an instance of an object.;
DEBUG: Finish sending metric.
DEBUG: 22:51:24 - GetReservationOrderId end processing.
```
### Environment data
```PowerShell
PS> $PSVersionTable
Name Value
---- -----
PSVersion 7.1.2
PSEdition Core
GitCommitId 7.1.2
OS Microsoft Windows 10.0.22509
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
```
### Module versions
```PowerShell
PS> Get-Module Az*
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Script 2.6.1 Az.Accounts {Add-AzEnvironment, Clear-AzContex…
Script 0.9.0 Az.Reservations {Get-AzReservation, Get-AzReservat…
```
### Error output
```PowerShell
PS> Resolve-AzError
WARNING: Upcoming breaking changes in the cmdlet 'Resolve-AzError' :
The `Resolve-Error` alias will be removed in a future release. Please change any scripts that use this alias to use `Resolve-AzError` instead.
Note : Go to https://aka.ms/azps-changewarnings for steps to suppress this breaking change warning, and other information on breaking changes in Azure PowerShell.
HistoryId: 5
Message : Object reference not set to an instance of an object.
StackTrace : at Microsoft.Azure.Commands.Reservations.Models.PSAppliedReservationOrderId..ctor(Ap
pliedReservations appliedReservationOrder)
at Microsoft.Azure.Commands.Reservations.Cmdlets.GetReservationOrderId.ExecuteCmdlet
()
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.<>c__3`1.b__3_0(T c)
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchron
ouslyOrAsJob[T](T cmdlet, Action`1 executor)
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchron
ouslyOrAsJob[T](T cmdlet)
at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
Exception : System.NullReferenceException
InvocationInfo : {Get-AzReservationOrderId}
Line : Get-AzReservationOrderId -SubscriptionId xxx -debug
Position : At line:1 char:1
+ Get-AzReservationOrderId -SubscriptionId xxx …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 5
HistoryId: 2
Message : Object reference not set to an instance of an object.
StackTrace : at Microsoft.Azure.Commands.Reservations.Models.PSAppliedReservationOrderId..ctor(Ap
pliedReservations appliedReservationOrder)
at Microsoft.Azure.Commands.Reservations.Cmdlets.GetReservationOrderId.ExecuteCmdlet
()
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.<>c__3`1.b__3_0(T c)
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchron
ouslyOrAsJob[T](T cmdlet, Action`1 executor)
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchron
ouslyOrAsJob[T](T cmdlet)
at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
Exception : System.NullReferenceException
InvocationInfo : {Get-AzReservationOrderId}
Line : Get-AzReservationOrderId -SubscriptionId xxx -debug
Position : At line:1 char:1
+ Get-AzReservationOrderId -SubscriptionId xxx …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 2
HistoryId: 1
Message : Object reference not set to an instance of an object.
StackTrace : at Microsoft.Azure.Commands.Reservations.Models.PSAppliedReservationOrderId..ctor(Ap
pliedReservations appliedReservationOrder)
at Microsoft.Azure.Commands.Reservations.Cmdlets.GetReservationOrderId.ExecuteCmdlet
()
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.<>c__3`1.b__3_0(T c)
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchron
ouslyOrAsJob[T](T cmdlet, Action`1 executor)
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchron
ouslyOrAsJob[T](T cmdlet)
at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
Exception : System.NullReferenceException
InvocationInfo : {Get-AzReservationOrderId}
Line : Get-AzReservationOrderId -SubscriptionId xxx
Position : At line:1 char:1
+ Get-AzReservationOrderId -SubscriptionId xxx …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 1
The Azure PowerShell team is listening, please let us know how we are doing: https://aka.ms/azpssurvey?Q_CHL=ERROR.
```
Contributor guide
Assessment
This issue has not been assessed yet.