I'm attempting to create a VM programmatically...actually, following an example in a book. Before running the program I went ahead and created an Azure AD application and service principal via the portal https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-create-service-principal-portal. (On a side note, maybe someone can explain to me why one needs to do this, but can create a VM straightaway via the portal without creating a service principal/AD app.)
While running the app, I'm able to successfully create the management client. Next step is to create the resource group, and that's where it fails with a "System.Net.Http.HttpRequestException: 'No such host is known.'" error. Please advise as to what could be the problem here. Thank you.
//Create the management client. This will be used for all the operations we will perform in Azure.
var credentials = SdkContext.AzureCredentialsFactory.FromFile("../../../azureauth.properties");
var azure = Azure.Configure().WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic).Authenticate(credentials).WithDefaultSubscription();
//Create a resource group
var groupName = "az204-ResourceGroup";
var vmName = "az204VMTesting";
var location = Region.USEast;
var vNetName = "az204VNET";
var vNetAddress = "172.16.0.0/16";
var subnetName = "az204Subnet";
var subnetAddress = "172.16.0.0/24";
var nicName = "az204NIC";
var adminUser = "azureadminuser";
var adminPassword = "Pa$$w0rd!2019";
Console.WriteLine($"Creating resource group {groupName} ... ");
//Below fails with 'No such host is known'
var resourceGroup = azure.ResourceGroups.Define(groupName).WithRegion(location).Create();