使用Azure SDK列出azure订阅中的所有虚拟机间歇性地失败

问题描述

我正在Azure功能应用程序(运行时3.1)中使用Azure的Fluent SDK,以列出订阅中的所有现有虚拟机。 但是,我注意到检索操作有时会失败。我今天收到以下异常:

操作被取消。 System.IO.IOException:无法从传输连接读取数据:由于线程退出或应用程序请求,I / O操作已中止。 ---> System.Net.sockets.socketException(995):由于线程退出或应用程序请求,I / O操作已中止。 ---内部异常堆栈跟踪的结尾--- 在System.Net.sockets.socket.Awaitablesocketasynceventargs.ThrowException(SocketError错误,CancellationToken cancelToken) 在System.Net.sockets.socket.Awaitablesocketasynceventargs.GetResult(Int16令牌) 在System.Net.Security.SslStream.g__InternalFillBufferAsync | 215_0 [TReadAdapter](TReadAdapter adap,ValueTask 1 task,Int32 min,Int32 initial) at System.Net.Security.SslStream.ReadAsyncInternal[TReadAdapter](TReadAdapter adapter,Memory 1个缓冲区)处 在System.Net.Http.httpconnection.FillAsync() 在System.Net.Http.httpconnection.ReadNextResponseHeaderLineAsync(BooleanfoldedHeadersAllowed) 在System.Net.Http.httpconnection.SendAsyncCore(HttpRequestMessage请求,CancellationToken cancelToken) 退出...

以下是我正在使用的:

using Microsoft.Azure.Management.Compute.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent;

var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(clientID,clientSecret,tenantID,AzureEnvironment.AzureGlobalCloud);
var azure = Microsoft.Azure.Management.Fluent.Azure.Authenticate(credentials).WithSubscription(subId);

            //Get all VMs,try 
            { 
                var vms = azure.VirtualMachines.List();
                //Loop through VMs
                foreach (IVirtualMachine vm in vms)
                {
                 //Rest of the code

呼叫 azure.VirtualMachines.List()间歇性失败的地方。我似乎不知道有什么问题吗?如果有人指出一些可能的原因,我可以检查出来。预先谢谢你。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)