question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

System.NullReferenceException when trying to get VM powerstate

See original GitHub issue

In 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:

https://imgur.com/HhI7AGQ

OS: Windows 10
IDE : Visual Studio 2017 ver. 15.9.10
Version of the Library used: 1.20.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
weidongxu-microsoftcommented, Sep 6, 2019

@Mi1an

Here is response from service team.

In scenarios where CRP does not know or can’t query the VM power state primarily because the Fabric/Host service is unavailable we explicitly don’t return the VM power state, the underlying contract that provides the VM power state is a nullable type from REST api perspective and the clients consuming it is expected to handle power state being unavailable.

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.

1reaction
weidongxu-microsoftcommented, Aug 29, 2019

@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.

                    PowerState powerState = vm.PowerState;
                    if (powerState == null)
                    {
                        // optionally with some delay
                        vm.RefreshInstanceView();
                        powerState = vm.PowerState;
                    }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Unknown powerstate status for Azure VM
I have a powershell script that starts up a sequence of Azure VMs by: Starting up a VM; Checking if the powerstate of...
Read more >
NullReferenceException when trying to get VM List - Activities
Hi, I'm quite new to UiPath and VM-Ware automation. To start, I wanted to get a list of all VMs on my test...
Read more >
.net - Get Azure VM PowerState in C#/dotnet using ...
I want to get the PowerState (on/off/restarting, etc.) of a known Azure VM instance in a C#/dotnet application using Azure.ResourceManager (not ...
Read more >
vRO javascript to get VM power state
I keep getting the error "cannot read property "powerState" from undefined. I have tried a few variations of code but below is the...
Read more >
Problem with adding VM's to Job
We have a script that daily fills our backups jobs by looking at custom properties defined in SCVMM and checks if the VM...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found