web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

Clone not working in HttpRequestMessage

(0) ShareShare
ReportReport
Posted on by 242

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

I have the same question (0)
  • Suggested answer
    Andre Ghazaleh Profile Picture
    870 on at

    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?

  • madiri Profile Picture
    242 on at

    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
    Bipin D365 Profile Picture
    28,983 Moderator on at

    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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Siv Sagar Profile Picture

Siv Sagar 93 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 76

#3
Martin Dráb Profile Picture

Martin Dráb 64 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans