Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Clone not working in HttpRequestMessage

Posted on by 240

Hi,

I am using  PowerApps-Samples Code from https://github.com/microsoft/PowerApps-Samples/tree/master/cds but i am getting error with 

Severity	Code	Description	Project	File	Line	Suppression State
Error	CS1061	'HttpRequestMessage' does not contain a definition for 'Clone' and no accessible extension method 'Clone' accepting a first argument of type 'HttpRequestMessage' could be found (are you missing a using directive or an assembly reference?)	Dynamics Webapi	C:\Users\lenova\source\repos\Dynamics Webapi\Dynamics Webapi\CDSWebApiService.cs	469	Active

i am using this file path Dynamics Webapi\Dynamics Webapi\CDSWebApiService.cs

The code as below

 private async Task SendAsync(
            HttpRequestMessage request,
            HttpCompletionOption httpCompletionOption = HttpCompletionOption.ResponseHeadersRead,
            int retryCount = 0)
        {
            HttpResponseMessage response;
            try
            {
                //The request is cloned so it can be sent again.
                response = await httpClient.SendAsync(request.Clone(), httpCompletionOption);
            }
            catch (Exception)
            {
                throw;
            }

            if (!response.IsSuccessStatusCode)
            {
                if ((int)response.StatusCode != 429)
                {
                    //Not a service protection limit error
                    throw ParseError(response);
                }
                else
                {
                    // Give up re-trying if exceeding the maxRetries
                    if (  retryCount >= config.MaxRetries)
                    {
                        throw ParseError(response);
                    }

                    int seconds;
                    //Try to use the Retry-After header value if it is returned.
                    if (response.Headers.Contains("Retry-After"))
                    {
                        seconds = int.Parse(response.Headers.GetValues("Retry-After").FirstOrDefault());
                    }
                    else
                    {
                        //Otherwise, use an exponential backoff strategy
                        seconds = (int)Math.Pow(2, retryCount);
                    }
                    Thread.Sleep(TimeSpan.FromSeconds(seconds));

                    return await SendAsync(request, httpCompletionOption, retryCount);
                }
            }
            else
            {
                return response;
            }
        }

Any help would be appreciated.thank you

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: Clone not working in HttpRequestMessage

    Hello,

    I fix that error by uninstalling Newtonsoft.json and then installig again.

    Right click on Project->Manage Nuget packages->Uninstall Newtonsoft.json->Install Newtonsoft.json

    ->Build your solution

    Make sure you have cloned entire project from github. Also, Update your .net framework to use 4.7.2

    Please mark my answer verified if i were helpful

  • madiri Profile Picture
    madiri 240 on at
    RE: Clone not working in HttpRequestMessage

    Hi,

    I am using following Reference let me know if i am missing any reference

    pastedimage1601790306287v2.png

    pastedimage1601790333612v3.png

    In code we are using 

    pastedimage1601790383347v4.png

    pastedimage1601790446130v5.png

    Framework i am using following screen

    pastedimage1601790154871v1.png

  • Suggested answer
    Andre Ghazaleh Profile Picture
    Andre Ghazaleh 870 on at
    RE: Clone not working in HttpRequestMessage

    Hi Rocky,

    The CS1061 error is caused when you try to call a method or access a class member that does not exist

    Maybe you are missing an assembly reference?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans