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.

[BUG] Managed disk in unmanaged disks collection

See original GitHub issue

In case that disk has filled in ‘Image.Uri’ property it is considered unmanaged although it is managed. This causes issues when listing disk via ‘vm.UnmanagedDataDisks’.

StackTrace: Object reference not set to an instance of an object. System.NullReferenceException at Microsoft.Azure.Management.Compute.Fluent.UnmanagedDataDiskImpl.VhdUri() at Microsoft.Azure.Management.Compute.Fluent.UnmanagedDataDiskImpl.Microsoft.Azure.Management.Compute.Fluent.IVirtualMachineUnmanagedDataDisk.get_VhdUri()

To Reproduce: Have managed disk with filled in ‘Image.Uri’ property, list unmanaged disks from vm and try to get VhdUri

Code snipped:

      public async Task ManagedDiskGetsListedAsUnmanagedExample(Microsoft.Azure.Management.Fluent.IAzure azure, CancellationToken ct)
       {
           var virtualMachines = await azure.VirtualMachines.ListAsync(true, ct);
           foreach (var vm in virtualMachines)
           {
               try
               {
                   foreach (var disk in vm.UnmanagedDataDisks.Values)
                   {
                       var uri = disk.VhdUri; // this throws null reference exception; the disk is managed
                   }
               }
               catch (Exception)
               {
                   bool allTrue; // it is true at any moment == all the conditions are true
                   allTrue = vm.Inner.StorageProfile.OsDisk.Vhd == null; // no vhd
                   allTrue = !string.IsNullOrEmpty(vm.Inner.StorageProfile.OsDisk.Image.Uri); // there is uri in Image
                   allTrue = !string.IsNullOrEmpty(vm.Inner.StorageProfile.OsDisk.ManagedDisk.Id); // there is this id and no vhd
               }
           }
       }

Expected behavior: Should be listed as managed disk

Setup:

  • OS: Win10
  • IDE : VS2019
  • Version: 1.35.0

Additional context: I was looking into library code and there is this function called IsManagedDiskEnabled

      public IReadOnlyDictionary<int, Microsoft.Azure.Management.Compute.Fluent.IVirtualMachineUnmanagedDataDisk> UnmanagedDataDisks()
       {
           Dictionary<int, IVirtualMachineUnmanagedDataDisk> dataDisks = new Dictionary<int, IVirtualMachineUnmanagedDataDisk>();
           if (!IsManagedDiskEnabled())
           {
               foreach (var dataDisk in this.unmanagedDataDisks)
               {
                   dataDisks.Add(dataDisk.Lun, dataDisk);
               }
           }
           return dataDisks;
       }

where there is IsOSDiskFromStoredImage if (IsOSDiskFromStoredImage(Inner.StorageProfile)) function. In my case this will result in managed disk to be considered unmanaged disk (causing problems described above). I Actually really don’t understand the code. From my perspective last line return Inner.StorageProfile.OsDisk.Vhd == null; should be enough. The logic seems to be unnecessary overcomplicated. Author probably knew better than me so it possible it has its reasons, but it would be nice to review (and maybe add some comments) that.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:9
  • Comments:27 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
Vaibhav-Agarcommented, Jan 22, 2021

I am looking in to this and will provide an update shortly.

0reactions
TravisCragg-MSFTcommented, Jan 27, 2022

As discussed above, this is an issue with a legacy SDK that is not supported. Please use the updated SDK.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Increased usage in unmanaged disk - Microsoft Q&A
Go to the Azure portal and select the Virtual Machines blade. · Select the VM that you want to check. · In the...
Read more >
Migrate a Windows virtual machine from unmanaged disks ...
How to migrate a Windows VM from unmanaged disks to managed disks by using PowerShell in the Resource Manager deployment model.
Read more >
Migrating a VM from a Managed Disk to an unmanaged Disk
You will first need to get the SAS token to read the managed disk, then initiate the copy to the storage account with...
Read more >
Unmanaged or Managed Azure Disk for small tenants?
1 Answer 1 ... Basically unmanaged disk you must handle by yourself, in case that an outage happens in Azure storage where your...
Read more >
Migrate Azure VM From Unmanaged Disks To Managed ...
In this article, we will show you how to convert and migrate Azure VM from Unmanaged Disks to Managed Disks.
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