From c65251374d2375d53acba96faeedfbd2d6fad30c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Cruz?= <137877982+JoaoCruz2001@users.noreply.github.com> Date: Tue, 27 Jun 2023 13:18:05 +0100 Subject: [PATCH] Fix "The request was already sent" error when getting app metadata When getting app metadata after an app has been added, if the metadataResponse.StatusCode == HttpStatusCode.NotFound then it will retry the request but without changing the HttpRequestMessage. This causes the following error "System.InvalidOperation: The request was already sent. Cannot send the same request multiple times". In this fix I included the creation of the HttpRequestMessage inside the while loop so that each time a retry is made, it creates a new HttpRequestMessage. --- src/lib/PnP.Framework/ALM/AppManager.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lib/PnP.Framework/ALM/AppManager.cs b/src/lib/PnP.Framework/ALM/AppManager.cs index e8eb7f084..07bf5b242 100644 --- a/src/lib/PnP.Framework/ALM/AppManager.cs +++ b/src/lib/PnP.Framework/ALM/AppManager.cs @@ -919,14 +919,14 @@ private static async Task GetAppMetaData(AppCatalogScope scope, Cli var metadataRequestUrl = $"{context.Web.Url}/_api/web/{(scope == AppCatalogScope.Tenant ? "tenant" : "sitecollection")}appcatalog/AvailableApps/GetById('{id}')"; - using (var metadataRequest = new HttpRequestMessage(HttpMethod.Get, metadataRequestUrl)) + while (returnValue == null && retryCount < 5) { - metadataRequest.Headers.Add("accept", "application/json;odata=nometadata"); - - await PnPHttpClient.AuthenticateRequestAsync(metadataRequest, context).ConfigureAwait(false); - - while (returnValue == null && retryCount < 5) + using (var metadataRequest = new HttpRequestMessage(HttpMethod.Get, metadataRequestUrl)) { + metadataRequest.Headers.Add("accept", "application/json;odata=nometadata"); + + await PnPHttpClient.AuthenticateRequestAsync(metadataRequest, context).ConfigureAwait(false); + // Perform actual post operation HttpResponseMessage metadataResponse = await httpClient.SendAsync(metadataRequest, new System.Threading.CancellationToken()); @@ -951,8 +951,8 @@ private static async Task GetAppMetaData(AppCatalogScope scope, Cli await Task.Delay(waitTime * 1000); // wait 10 seconds } } - return returnValue; - } + } + return returnValue; } #endregion }