繁体   English   中英

Azure管理客户端不返回任何资源组

[英]azure management client doesn't return any resource group

我是天青。 我正在尝试创建ResourceGroup,然后尝试部署VM。 但是在访问资源组期间出现异常。

我正在遵循此处给出的MSDN示例: https : //docs.microsoft.com/zh-cn/azure/virtual-machines/windows/csharp-template

我尝试了其他订阅,但没有运气。 在网上找不到有关此问题的任何指针,否则我可能会错过。 如果您能帮助我,请告诉我。

谢谢。


//AppId,Key,TenetId are correct
var credentials = SdkContext.AzureCredentialsFactory
                .FromServicePrincipal(ApplicationID, Key, TenetID,
                    new AzureEnvironment()
                    {
                        AuthenticationEndpoint = @"https://login.windows.net/",
                        ManagementEndpoint = @"https://management.core.windows.net/",
                        ResourceManagerEndpoint = @"https://management.azure.com/",
                        GraphEndpoint = @"https://graph.windows.net/",
                    });

 var azure = Azure
                .Configure()
                .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
                .Authenticate(credentials)
                .WithSubscription(AzureProperties.SubscriptionId);

            var groupName = "MyresourceGroup1";
            var location = Region.USWest;

//Exception comes at here.
            var resourceGroup = azure.ResourceGroups.Define(groupName)
                .WithRegion(location)
                .Create();

//异常详细信息。

System.ArgumentNullException
  HResult=0x80004003
  Message=Value cannot be null.
Parameter name: value
  Source=mscorlib
  StackTrace:
   at System.String.EndsWith(String value, StringComparison comparisonType)
   at Microsoft.Azure.Management.ResourceManager.Fluent.Authentication.AzureCredentials.<ProcessHttpRequestAsync>d__24.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Microsoft.Azure.Management.ResourceManager.Fluent.ResourceGroupsOperations.<CreateOrUpdateWithHttpMessagesAsync>d__6.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Management.ResourceManager.Fluent.ResourceGroupImpl.<CreateResourceAsync>d__26.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Management.ResourceManager.Fluent.Core.ResourceActions.Creatable`4.<Microsoft-Azure-Management-ResourceManager-Fluent-Core-ResourceActions-IResourceCreator<IResourceT>-CreateResourceAsync>d__15.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Management.ResourceManager.Fluent.Core.DAG.CreatorTaskItem`1.<ExecuteAsync>d__6.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Management.ResourceManager.Fluent.Core.DAG.TaskGroupBase`1.<ExecuteNodeTaskAsync>d__14.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Management.ResourceManager.Fluent.Core.Extensions.Synchronize[TResult](Func`1 function)
   at Microsoft.Azure.Management.ResourceManager.Fluent.Core.ResourceActions.Creatable`4.Create()
   at pvt_CreateVM.AzureVMManager.CreateVM()
   at pvt_CreateVM.Program.Main(String[] args)

我认为目前的代码失败,因为你没有设置任何值KeyVaultSuffix属性AzureEnvrionment你已经初始化。

猜测是您共享的错误信息,但是在查看了.NET的Azure管理库的相关源代码之后,我才说了这一点

(附带说明,任何人都可以做到这一点很棒。这是一个链接

    public async override Task ProcessHttpRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    {
        var adSettings = new ActiveDirectoryServiceSettings
        {
            AuthenticationEndpoint = new Uri(Environment.AuthenticationEndpoint),
            TokenAudience = new Uri(Environment.ManagementEndpoint),
            ValidateAuthority = true
        };
        string url = request.RequestUri.ToString();
        if (url.StartsWith(Environment.GraphEndpoint, StringComparison.OrdinalIgnoreCase))
        {
            adSettings.TokenAudience = new Uri(Environment.GraphEndpoint);
        }

        string host = request.RequestUri.Host;

        // I guess this is where your code is failing currently. 
        if (host.EndsWith(Environment.KeyVaultSuffix, StringComparison.OrdinalIgnoreCase))
        {

怎么修

除非有充分的理由,否则我不会初始化AzureEnvironment对象,而是使用已经可用的值,因为这将确保所有必需的属性都具有正确的值。

示例: AzureEnvironment.AzureGlobalCloud 在这里查看所有可能的值

在初始化AzureEnvironment的位置更改此代码

var credentials = SdkContext.AzureCredentialsFactory
            .FromServicePrincipal(ApplicationID, Key, TenetID,
                new AzureEnvironment()
                {
                    AuthenticationEndpoint = @"https://login.windows.net/",
                    ManagementEndpoint = @"https://management.core.windows.net/",
                    ResourceManagerEndpoint = @"https://management.azure.com/",
                    GraphEndpoint = @"https://graph.windows.net/",
                });

到此代码

var credentials = SdkContext.AzureCredentialsFactory
    .FromServicePrincipal(clientId,
    clientSecret,
    tenantId, 
    AzureEnvironment.AzureGlobalCloud);

如果您出于某种原因没有一个可用的环境值足够好,请确保初始化AzureEnvironment的所有必需属性

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM