尝试向Azure管理SDK进行身份验证时发生异常 [英] Exception while trying to authenticate to the azure management SDK

查看:112
本文介绍了尝试向Azure管理SDK进行身份验证时发生异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在v1或v2 azure函数应用程序中尝试使用.net管理SDK(Microsoft.Azure.Management.Fluent)对我的Azure帐户进行身份验证时,出现以下异常:

I am getting the following exception while trying to authenticate to my azure account using the .net management SDK (Microsoft.Azure.Management.Fluent) in a v1 or v2 azure functions app:

Full Exception : Exception while executing function: status 
System.ArrayTypeMismatchException : Attempted to access an element as a type incompatible with the array.
at System.Collections.Generic.List`1.Add(T item)
at Microsoft.Azure.Management.ResourceManager.Fluent.Core.ProviderRegistrationDelegatingHandler..ctor(AzureCredentials credentials)
at Microsoft.Azure.Management.ResourceManager.Fluent.Core.AzureConfigurable`1.BuildRestClient(AzureCredentials credentials)
at Microsoft.Azure.Management.Fluent.Azure.Configurable.Microsoft.Azure.Management.Fluent.Azure.IConfigurable.Authenticate(AzureCredentials credentials)
at VMOperations.VMOperations.CheckVM() at C:\Users\<username>\source\repos\ConsoleApp1\ConsoleApp1\VMOperations.cs : 22
at async FunctionApp3.Status.Run(HttpRequestMessage req,TraceWriter log)
at async Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.InvokeAsync[TReflected,TReturnValue](Object instance,Object[] arguments)
at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.InvokeAsync(IFunctionInvoker invoker,ParameterHelper parameterHelper,CancellationTokenSource timeoutTokenSource,CancellationTokenSource functionCancellationTokenSource,Boolean throwOnTimeout,TimeSpan timerInterval,IFunctionInstance instance)
at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithWatchersAsync(IFunctionInstance instance,ParameterHelper parameterHelper,TraceWriter traceWriter,CancellationTokenSource functionCancellationTokenSource)
at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(??)
at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(??)
End of inner exception

引起异常的代码如下:

AzureCredentials credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(AzureManagementData.CLIENTID, AzureManagementData.SECRET, AzureManagementData.DOMAIN, AzureEnvironment.AzureGlobalCloud);

Azure.IConfigurable azure = .configure();

Azure.IConfigurable azure = Azure.Configure();

azure = azure.WithLogLevel(HttpLoggingDelegatingHandler.Level.BodyAndHeaders);

azure = azure.WithLogLevel(HttpLoggingDelegatingHandler.Level.BodyAndHeaders);

Azure.IAuthenticated authenticated = azure.Authenticate(credentials);  //这里发生异常

Azure.IAuthenticated authenticated = azure.Authenticate(credentials);  // exception occurs here

IAzure authenticated2 = authenticated.WithDefaultSubscription();

IAzure authenticated2 = authenticated.WithDefaultSubscription();

有人知道,是什么导致此异常?我已经看过是否可以自己解决这个问题,但是没有找到有关此异常的任何有用信息.

Does anyone know, what is causing this exception? I Looked already if I can solve this on my own, but didn't find any helpful information about this exception.

当我在普通控制台应用程序中运行此异常时,不会发生此异常.

This exception does not occur, when I run this in a normal console application.

推荐答案

基于您的错误堆栈已经共享,例外来自

Based on the error stack that you've shared, the exception is from this line of the SDK.

从那以后,我认为您正面临与此

And from that, I think you are facing the same issue as mentioned in this SO thread.

您可以尝试在.csproj文件中指定Newtonsoft.Json的特定版本(我认为应该尝试最新版本),然后重试吗?

Could you try specifying a specific version of Newtonsoft.Json (I think trying the latest should do) in your .csproj file and try again?


这篇关于尝试向Azure管理SDK进行身份验证时发生异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆