首页 > 解决方案 > System.IO.FileNotFoundException 上 System.Runtime.CompilerServices.AsyncTaskMethodBuilder

问题描述

我有以下代码

    try
    {
        using (var client = HttpClientBuilder.CreateClient(PingTimeoutMilliseconds, true))
        {
            var response = await Policy
                .Handle<Exception>(ex => ex is HttpRequestException || ex is TaskCanceledException)                        
                .WaitAndRetryAsync(new[]
                {
                    TimeSpan.FromSeconds(1),
                    TimeSpan.FromSeconds(3)
                }, (ex, timeSpan, retryCount, context) =>
                {
                    loggerService.Log(ex);
                    loggerService.Log($"Ping request failed. Waiting {timeSpan} seconds before next retry. Retry attempt {retryCount}");
                })
                .ExecuteAsync(() => client.SendAsync(new HttpRequestMessage(HttpMethod.Head, uri)));
            IsInternetAvailable = response.IsSuccessStatusCode;
            return response.IsSuccessStatusCode;
        }
    }

一些客户抱怨异常

Uitzonderings 信息:System.IO.FileNotFoundException

System.IO.FileNotFoundException

bij Showpad.OutlookDesktopAddIn.Infrastructure.Helpers.PingHelper+<IsInternetAvailableAsync>d__5.MoveNext()
    System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Start[[Showpad.OutlookDesktopAddIn.Infrastructure.Helpers.PingHelper+<IsInternetAvailableAsync>d__5, Showpad.OutlookDesktopAddIn, Version=2.7.6.0, Culture=neutral, PublicKeyToken=null]](<IsInternetAvailableAsync>d__5 ByRef)

我可能怀疑第 5 行等待策略的 Polly 库可能有问题(因为存在 IO 异常)

using Polly;

标签: c#asp.net.netasp.net-mvcpolly

解决方案


FileNotFoundException有一个名为FileName( 1 )的属性。

请先检查一下,原因也请仔细检查FusionLog( 1 )。


推荐阅读