I received this error:
Unhandled Exception: Microsoft.Rest.Azure.CloudException: The client 'XXX' with object id 'XXX' does not have authorization to perform action 'Microsoft.Resources/subscriptions/resourcegroups/write' over scope '/subscriptions/YYY/resourcegroups/FluentRG' or the scope is invalid. If access was recently granted, please refresh your credentials.
I have logged in my Azure Account into VS Code, and I have granted permission to my email address as a contributor in my current subscription. Still, this exception is seen.
using System;
using Microsoft.Azure.Management.Compute.Fluent;
using Microsoft.Azure.Management.Compute.Fluent.Models;
using Microsoft.Azure.Management.Fluent;
namespace RESTApp
{
class Program
{
static void Main(string[] args)
{
var azure = Azure.Authenticate("Azure-authentication.txt").WithDefaultSubscription();
Console.WriteLine("Creating a new VM...");
var windowsVM = azure.VirtualMachines.Define("VMCreatedWithFluent")
.WithRegion("West Europe")
.WithNewResourceGroup("FluentRG")
.WithNewPrimaryNetwork("10.0.0.0/28")
.WithPrimaryPrivateIPAddressDynamic()
.WithNewPrimaryPublicIPAddress("fluentdns")
.WithPopularWindowsImage(KnownWindowsVirtualMachineImage.WindowsServer2012Datacenter)
.WithAdminUsername("serverAdmin")
.WithAdminPassword("mySuperSecurePassword18")
.WithSize(VirtualMachineSizeTypes.StandardDS3V2)
.Create();
Console.WriteLine("Successfully created a new VM: {0}!", windowsVM.Id);
Console.WriteLine("Press any key to exit...");
Console.ReadLine();
}
}
}
