Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CloudBlockBlob.DownloadText() handles UTF8 BOM incorrectly #626

Closed
rzio opened this issue May 5, 2014 · 2 comments
Closed

CloudBlockBlob.DownloadText() handles UTF8 BOM incorrectly #626

rzio opened this issue May 5, 2014 · 2 comments

Comments

@rzio
Copy link

rzio commented May 5, 2014

CloudBlockBlob.DownloadText() behaves differently than File.ReadAllText in respect to UTF8 pre-amble/BOM

Repro:
Create an XML File in Visual Studio and upload it to a Cloud Blob container. The file will begin with a BOM (EF BB BF). Then download it using CloudBlockBlob.DownloadText() and pass the resulting string to XDocument.Parse. The parser will fail with XMLException - "Data at the root level is invalid. Line 1, position 1.".
Failing code:

var storageAccount = CloudStorageAccount.Parse("connectionString");
var blobClient = storageAccount.CreateCloudBlobClient();
var container = blobClient.GetContainerReference("MyContainer");
var blob = container.GetBlockBlobReference("my.xml");
var s = blob.DownloadText();
var x = XDocument.Parse(s);

A workaround suggested at http://stackoverflow.com/questions/2111586/parsing-xml-string-to-an-xml-document-fails-if-the-string-begins-with-xml by Dave Cluderay suggests passing the read string through StreamReader.
Working code

        var storageAccount = CloudStorageAccount.Parse("connectionString");
        var blobClient = storageAccount.CreateCloudBlobClient();
        var container = blobClient.GetContainerReference("MyContainer");
        var blob = container.GetBlockBlobReference("my.xml");
        var s = blob.DownloadText();
        using (var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(s)))
        {
            using (var streamReader = new StreamReader(memoryStream))
            {
                var x = XDocument.Load(streamReader);
            }
        }
@ahmetb
Copy link

ahmetb commented May 7, 2014

Please open this issue to https://github.com/WindowsAzure/azure-storage-net repository.

@rzio
Copy link
Author

rzio commented May 7, 2014

Moved issue to: Azure/azure-storage-net#46

@rzio rzio closed this as completed May 7, 2014
@github-actions github-actions bot locked and limited conversation to collaborators Mar 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants