System.NullReferenceException when trying to get VM powerstate
See original GitHub issueIn 3/10 when calling PowerState.Value of VM i get NullReferenceException. It is always on different VM. I am listing 100 VMs and this exception is sometimes on 1 VM, sometimes on 3 VMs, sometimes 5 VMs or just everything working without problems. I don´t see any logical reason to this exception. VMs are okay with state Running or Deallocated nothing what can cause exception.
Stack Trace:
[Line 41]: string azurePowerState = virtualMachine.PowerState.Value.ToString();
Exception:
System.NullReferenceException: Object reference not set to an instance of an object. at azureStartStopGuardJob.Program.AzureMachineLoader.LoadMachines() in C:\Users\admin\source\repos\azureStartStopGuardJob\azureStartStopGuardJob\Program Loaders\AzureMachineLoader.cs:line 41 pre VM:
Image:
OS: Windows 10
IDE : Visual Studio 2017 ver. 15.9.10
Version of the Library used: 1.20.0
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (5 by maintainers)
Top GitHub Comments
@Mi1an
Here is response from service team.
Basically there is certain chance that service does not know VM power state. It would be similar to PowerState.UNKNOWN.
For compatibility (other user might already retrying on null), SDK would still return null if service does not provide this state. We will improve method documentation to indicate this situation and advice on refresh/retry.
@Mi1an
I can reproduce this issue with local test after several hours of looping. We are contacting service team to verify.
Meantime, I think one option is to guard this NPE and retry in code. E.g.