none
Outofmemory DownloadText() downloading Blob RRS feed

  • Question

  • with this code:

    CloudBlockBlob blockBlob = syncMsgContainer.GetBlockBlobReference(blobId);
                    return blockBlob.DownloadText();

    We get this error intermittently. Is there any suggestions on how to best troubleshoot this? We have a Blob that is about 80MB.

    'Insert'  Base Exception:  Type: System.OutOfMemoryException  Assembly: System.OutOfMemoryException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089  Source: mscorlib  Message: Exception of type 'System.OutOfMemoryException' was thrown.  StackTrace:    at System.Text.UTF8Encoding.GetString(Byte[] bytes, Int32 index, Int32 count)     at Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.DownloadText(Encoding encoding, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)     at Common.Azure.BlobContainerWrapper.DownloadBlob(String blobId)     at DbSyncService.Components.MessageProcessor.GenerateDMLInsertStatement(TableDataChanges change, Dictionary`2 columnTypes)     at DbSyncService.Components.MessageProcessor.ApplyDMLTableDataChange(TableDataChanges change, Guid srcLocationId)     at DbSyncService.Components.MessageProcessor.ProcessDataDMLMessage(IncomingBusMessage msg, Guid srcLocationId)  TargetSite: GetString      

    Wednesday, June 12, 2019 4:04 PM

All replies

  • It is likely that your blob exceeds the memory allowance for the application, try and use a Streaminstead with the DownloadToStreamAsync method .

    So instead of reading the entire file in one go you read them in chunks. 

    // Retrieve reference to a blob named "filename"
                CloudBlockBlob blockBlob2 = container.GetBlockBlobReference(filename);
    
                string text;
                using (var memoryStream = new MemoryStream())
                {
                    blockBlob2.DownloadToStream(memoryStream);
                    text = System.Text.Encoding.UTF8.GetString(memoryStream.ToArray());
                }
    
                return text;
            }

    Friday, June 14, 2019 4:24 AM
    Moderator
  • Any updates on this ?
    Monday, June 17, 2019 8:12 AM
    Moderator