Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
167 views
in Technique[技术] by (71.8m points)

c# - Call http with larger json error in the emulator

When I make this same call through the emulator, passing as a parameter a higher limit, consequently the json will be higher, this error is shown, but if the limit is lower and the json smaller, it does not show the error.

And by my physical cell phone the error is not disassembling at any time

Error: not met, function:get_this_async_id, Could not execute the method because the containing type 'System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[TResult_REF]', is not fully instantiated. assembly: type: member:(null)

I'm using the polly library to make http calls

my code

public async Task<Hero> GetHeroesWichFactory(string limite)
{
    var func = new Func<Task<Hero>>(() => HeroGetRequest(limite));

     //main function
    return await _networkService.WaitAndRetry<Hero>(func, new Func<int,
        TimeSpan>(time => TimeSpan.FromSeconds(Math.Pow(2, time))), 3);
}

async Task<Hero> HeroGetRequest(string limite)
{
    var httpClient = new HttpClient();
    var response = await httpClient.GetAsync(GetUrl(limite));

    var rawResponse = await response.Content.ReadAsStringAsync();
    return JsonConvert.DeserializeObject<Hero>(rawResponse);
}

public async Task<T> WaitAndRetry<T>(Func<Task<T>> func, Func<int, TimeSpan> sleepDurationProvider, int retryCount)
{
    return await WaitAndRetryInner<T>(func, sleepDurationProvider, retryCount);
}

internal async Task<T> WaitAndRetryInner<T>(Func<Task<T>> func, Func<int, TimeSpan> sleepDurationProvider, int retryCount = 1, Func<Exception, TimeSpan, Task> onRetryAsync = null)
{
    var onRetryInner = new Func<Exception, TimeSpan, Task>((e, t) =>
    {
        return Task.Factory.StartNew(() => {
            System.Diagnostics.Debug.WriteLine($"Retrying in {t.ToString("g")} due to exception '{(e.InnerException ?? e).Message}'");
        });
    });

    return await Policy.Handle<Exception>().WaitAndRetryAsync(retryCount, sleepDurationProvider, onRetryAsync ?? onRetryInner).ExecuteAsync<T>(func);
}

note: sometimes the error stops happening in the emulator, and suddenly comes back, without having had any changes in the code

accept code suggestion please, this is the repository https://github.com/gabriel-projetos/AppMarvel


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...