I want to resize my os disk space but getting "Disk resizing is allowed only when creating a VM or when the VM is deallocated."
Microsoft.Azure.Management.ResourceManager.Fluent.Core.RestClient restClient = GetRestClient(requestObject);
var computeClient = new ComputeManagementClient(restClient) { SubscriptionId = requestObject.SubscriptionId };
var ObjVirtualMachines = computeClient.VirtualMachines.GetAsync(requestObject.ResourceGroupName, requestObject.VirtualMachineName, null, new System.Threading.CancellationToken()).Result;
var disktodetach = ObjVirtualMachines.StorageProfile.OsDisk;
ObjVirtualMachines.StorageProfile.OsDisk.DiskSizeGB = requestObject.DiskSize;
var newUpdateVM = computeClient.VirtualMachines.CreateOrUpdateAsync(requestObject.ResourceGroupName, requestObject.VirtualMachineName, ObjVirtualMachines).Result;
resizeDisk = newUpdateVM.ProvisioningState;
Thank you 1_bug. Posting your suggestions as answer to help other community members.
you cannot Increase the disk size for a running VM. Rather you can increase the disk size of a VM by shutting down the VM and following the below code.
Before using the above code check weather your code includes creationData.creationoption field is empty.
for further information check Disk.DiskSizeGB Property