ShareFile-NET
ShareFile-NET copied to clipboard
ShareFile.Api.Client.Exceptions.InvalidApiResponseException while calling Delete(Uri).ExecuteAsync(cancellationToken)
While trying to delete a file uploaded to a folder I made a call Delete() calling like-
await _sfClient.Items.Delete(fileUrl).ExecuteAsync(cancellationToken);
_sfclient is injected into the class and I am authenticating the client right before the Delete call.
The file is getting deleted successfully but after the execution completed I am getting the below exception.
Name $exception Value {"Unable to retrieve HttpResponseMessage.Content"} Type ShareFile.Api.Client.Exceptions.InvalidApiResponseException
stacktrace:
at ShareFile.Api.Client.Requests.Providers.AsyncRequestProvider.HandleNonSuccess(HttpResponseMessage responseMessage, Int32 retryCount, Type expectedType)
at ShareFile.Api.Client.Requests.Providers.AsyncRequestProvider.HandleResponse(HttpResponseMessage httpResponseMessage, ApiRequest request, Int32 retryCount, Boolean tryResolveUnauthorizedChallenge)
at ShareFile.Api.Client.Requests.Providers.AsyncRequestProvider.ExecuteAsync(IQuery query, CancellationToken token)
at MyapplicationNamespace.Services.CitrixService.DeleteShareFileAsync(Uri fileUrl, CancellationToken cancellationToken)
the API troubleshooting documentation clearly says ,
204 No Content This response is commonly used for DELETE operations, and it indicates that the resource was deleted successfully.
But why this is throwing the exception? this is getting logged in my app insight every time I try to delete the file passing the Uri.
How to just simply delete the file without any exception?
I figured this out. First get the item by passing the same url and then delete the item by passing the url as, item.url into Delete()
var fileItem = await _sfClient.Items.Get(fileUrl).ExecuteAsync(cancellationToken); await _sfClient.Items.Delete(item.url).ExecuteAsync(cancellationToken);