'Receive error "There is currently a lease on the blob and no lease ID was specified" when trying to delete a leased blob using the C# BlobClient?
I have a Blob that I am accessing thus:
BlobContainerClient blobContainerClient = blobServiceClient.GetBlobContainerClient(Container);
BlobClient blobClient = blobContainerClient.GetBlobClient(key);
BlobLeaseClient blobLeaseClient = blobLeaseClientWrapper.GetBlobLeaseClient(blobClient);
blobLeaseClient.Acquire(TimeSpan.FromSeconds(60));
When I come to delete the blob using:
blobClient.Delete();
I get the error:
There is currently a lease on the blob and no lease ID was specified in the request
I've tried breaking the lease but I still get the same error:
blobLeaseClient.Break();
blobClient.Delete();
How do I delete a leased blob?
Solution 1:[1]
This doesn't seem to be very well documented. The only reference I could find was this unhelpful response in the MSdocs github site and this old question about VMs from 2013.
A bit of digging in the classes unearthed this overload that seems to fix the problen:
blobClient.Delete(DeleteSnapshotsOption.IncludeSnapshots, new BlobRequestConditions()
{
LeaseId = blobLeaseClient.LeaseId
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Liam |
