我对C#来说比较新,在处理一个项目以旋转虚拟机(以及MS Azure中的支持资源)时遇到了此错误。System.ArgumentNullException:'值不能为空。'
我使用的代码是下面的一个:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.Management.Compute.Fluent;
using Microsoft.Azure.Management.Compute.Fluent.Models;
using Microsoft.Azure.Management.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent.Core;
namespace ConsoleApp1
{
class Program
{
private static void Main(string[] args)
{
var credentials = SdkContext.AzureCredentialsFactory.FromFile(Environment.GetEnvironmentVariable("AZURE_AUTH_LOCATION"));
var azure = Azure
.Configure()
.WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
.Authenticate(credentials)
.WithDefaultSubscription();
我也有一个“azureauth.properties.txt”文件我用来设置代码中引用上面"AZURE_AUTH_LOCATION"
一个新的环境路径。
要设置我用简单的PS命令的路径:
[Environment]::SetEnvironmentVariable("AZURE_AUTH_LOCATION", "C:\MY-PATH\azureauth.properties", "User")
的azureauth.properties文件包含简单的租户/应用/钥匙ID格式
subscription=<subscription-id>
client=<application-id>
key=<authentication-key>
tenant=<tenant-id>
managementURI=https://management.core.windows.net/
baseURL=https://management.azure.com/
authURL=https://login.windows.net/
graphURL=https://graph.windows.net/
每当我试图运行该项目我得到一个错误说:
System.ArgumentNullException:'值不能为空'。
专为线:
var credentials = SdkContext.AzureCredentialsFactory.FromFile(Environment.GetEnvironmentVariable("AZURE_AUTH_LOCATION"));
任何想法,为什么?
检查从* Environment.GetEnvironmentVariable(“AZURE_AUTH_LOCATION”)的结果* - 看来,这是空,因此,你必须考虑为什么环境变量是未知的过程 –
您可以添加堆栈跟踪更好的帮助? –
请尝试重新启动Visual Studio并再试一次,然后它应该工作。 –