find a location for property in a new city

Sunday 11 November 2012

Upgrading Azure Storage Client Library to v2.0 from 1.7

I upgraded Azure Storage to version 2.0 from 1.7 and I've found a number of differences when using storage. I thought how I'd document how I upgraded these more awkward bits of Azure Storage in version 2.0.

DownloadByteArray has gone missing

For whatever reason DownloadByteArray has been taken from me. So has DownloadToFile, DownloadText, UploadFromFile, UploadByteArray, and UploadText

Without too much whinging I'm just going to get on and fix it. This is what was working PERFECTLY FINE in v1.7:

public byte[] GetBytes(string fileName)
{
    var blob = Container.GetBlobReference(fileName);
    return blob.DownloadByteArray();
}

And here is the code modified to account for the face that DownloadByteArray no longer exists in Azure Storage v2.0:

public byte[] GetBytes(string fileName)
{
    var blob = Container.GetBlockBlobReference(fileName);
    using (var ms = new MemoryStream())
    {
        blob.DownloadToStream(ms);
        ms.Position = 0;
        return ms.ToArray();
    }
}

How to get your CloudStorageAccount

Another apparently random change is that you can't get your storage account info in the same way as you used to. You used to be able to get it like this in Storage Client v1.7:

var storageAccountInfo = CloudStorageAccount.FromConfigurationSetting(configSetting);
var tableStorage = storageAccountInfo.CreateCloudTableClient();

But in Azure Storage v2.0 you must get it like this:

var storageAccountInfo = CloudStorageAccount.Parse(
            CloudConfigurationManager.GetSetting(configSetting));
var tableStorage = storageAccountInfo.CreateCloudTableClient();

Why?.. not sure. I have had problems with getting storage account information before so maybe this resolve that.

What happened to CreateTableIfNotExist?

Again, it's disappeared but who cares.. Oh you do? Right well let's fix that up. So, in Azure Storage Client v1.7 you did this:

var tableStorage = storageAccountInfo.CreateCloudTableClient();
tableStorage.CreateTableIfNotExist(tableName);

But now in Azure Storage Client Library v2.0 you must do this:

var tableStorage = storageAccountInfo.CreateCloudTableClient();
var table = tableStorage.GetTableReference(tableName);
table.CreateIfNotExists();

Attributes seem to have disappeared and LastModifiedUtc has gone

Another random change that possibly doesn't achieve anything other than making you refactor your code. This was my old code from Storage Library Client v1.7:

var blob = BlobService.FetchAttributes(FileName);
if (blob == null || blob.Attributes.Properties.LastModifiedUtc < DateTime.UtcNow.AddHours(-1))
{
    ...
}

But now it should read like this because thought it looks prettier (which it does in fairness).

var blob = BlobService.FetchAttributes(FileName);
if (blob == null || blob.Properties.LastModified < DateTimeOffset.UtcNow.AddHours(-1))
{
    ...
}

Change your development storage connection string

This is just a straight bug so that's excellent. I was getting a useless exception stating "The given key was not present in the dictionary" when trying to create a CloudStorageAccount reference. To resolve this change your development environment connection string from UseDevelopmentStorage=true to UseDevelopmentStorage=true;DevelopmentStorageProxyUri=http://127.0.0.1 then it will magically work.

Bitch and moan

Apologies for the whingy nature of this post, I'm quite a fan of Azure but I have wasted about 3-4 hours with this "upgrade" from Azure Storage Client Library 1.7 to 2.0. It's been incredibly frustrating particularly since there seems to be no obvious reason why these changes were made. I just can't believe the amount of breaking changes when I haven't really written that much Azure storage code.

Randomly taking out nice methods like DownloadByteArray and DownloadText is surely a step backwards no? Or randomly renaming CreateIfNotExist() to CreateIfNotExists()... what is the point in that?!

I remember when upgrading to ASP.NET 4 from 3.5, I spent very little time working through breaking changes and I have 100 times more .NET code than I do Azure Storage code. As well as that, I was well aware of the many improvements with that .NET version update, with this Azure Storage update I have no idea what I'm getting. No matter the improvements, it is just an Azure storage API and this number of breaking changes, often for the benefit of syntax niceties is just unnacceptable.

Oh, if you are still in pain doing this I have found a complete list of breaking changes in this update along with minimal explanations here.

Follow britishdev on Twitter

59 comments:

  1. You 'Bitch and moan', so that I didn't have to!
    Thanks :-)

    The problem was made worse (IMO) by the pretty rubbish pages MS put out to 'support' this.

    The 'breaking changes and migration guide' did very little other than tell me what I already knew - my code wasn't going to work any more.
    And the 'deep dive', while informative for writers of new code, ignores the topic of migration.

    Ultimately it feels like the 2.0 lib is 'better' than the 1.7 lib, at least for new projects.
    I do have a few concerns about needing to have BOTH if I want diagnostics to work though.

    ReplyDelete
    Replies
    1. Thanks a lot for the opportunity to read such interesting information! TOP-RATED moving company in Toronto Ontario CA long distance moving all Canadian provinces and residential moving services. Find the best RESIDENTIAL MOVING, STORAGE SERVICES, COMMERCIAL MOVING
      Whether you are renovating, moving house or going abroad, we can take care of your storage needs by providing long and short-term storage solutions. looking for a trusted moving company in Calgary, a cosmopolitan Alberta city, recommendation Calgary moving services We add great flavor to the experience of moving and make it an awesome ordeal for you

      Delete
  2. It is very nice and informative blog through which we gain a lot information for our some purpose. Upgrading Azure Storage really awesome post. New Grass Mesh available in different sizes visit http://groundreinforcementmeshuk.co.uk/grass-mats.html for more detail.

    ReplyDelete
  3. Creating your own Infographic can be made easy with these six great Website suggestions for Infographic Templates and Free Infographic Downloads. Infographics are great for a number of purposes whether you are creating a timeline of information, analyzing the findings of a study or assembling a how to guide. See more infographic design online

    ReplyDelete
  4. Here we present to introduce to all visitors in this great blog. and thank you for allowing me . cara menggugurkan kandungan

    ReplyDelete
  5. nice post friend , Thank you for sharing with us, and we sincerely hope you will continue to update or post other articles

    mutilateadoll23.com
    luffygames.com

    ReplyDelete
  6. Thanks to this article I can learn more.http://chouraha.com/si-kaise-bane-sub-inspector-taiyari-kaise-kare/ Expand your knowledge and abilities. Actually the article is very practical.

    ReplyDelete
  7. Motifz Designer Lawn. 1, 2 & 3 Piece Unstitched Premium Embroidered Lawn 2019, Premium Lawn, Lawn 2019, Best lawn collection, Motifz, Best Lawn in Pakistan, Shipping worldwide. Stitching option available.

    ReplyDelete
  8. Buy Premium lawn Online for Women's at best prices available at Motifz. ✓ Latest Fashion, ✓ Trendy Designs ➤ Shop Now!

    ReplyDelete
  9. 123movies Very good article and I like it. Thank you for giving me information

    ReplyDelete
  10. Fake driving license online at cheap price
    Welcome to Buy All Documents online site. We are a licensee of New Life Identity and are recognised internationally as a leading company in document security feature technologies. Since opening 2011, we have been favourites in the fake ID cards online, real and fake passport industry for innovative ideas, superior customer care and quality. Buy Real Fake Documents offer 100% authentic & cheap fake driving license online to UK, US, Canada and all over the world.

    For more details you can visit our website: https://buyalldocument.com/ OR WhatsApp: +1(443) 351-8162 OR Email us at buyrealfake.documents@yandex.com

    ReplyDelete
  11. Wholesale printed custom perfume boxes with the highest quality and affordable prices. Free worldwide Delivery and free Custom Perfume Boxes design.

    ReplyDelete
  12. Buy online wholesale printed custom candle boxes and packaging at easy prices and shipping worldwide, with 24/7 customer support. Get a free custom quote now!!

    ReplyDelete
  13. Buy online wholesale lipstick boxes and packaging at seashore packaging at the easy price Free shipping worldwide with 24/7 customer support.

    ReplyDelete
  14. Blackbird packaging provide you with any size, shape design, CBD boxes sooner than any other packaging competitor in the market

    ReplyDelete
  15. Packaging town is a one-stop solution for the short-run Custom Packaging, Wholesale CBD Boxes needs, and supplies at ease.

    ReplyDelete
  16. Blackbird packaging provide you with any size, shape design, bath bomb display boxes sooner than any other packaging competitor in the market

    ReplyDelete
  17. Packaging town is a one stop solution for the short-run custom tuck boxes needs and supplies. At affordable prices. Request a free quote now.

    ReplyDelete
  18. custom printed mylar bags uk in stock now. Ready made Cali pack designs. Fast Shipping at Your Supplies. Custom designs available

    ReplyDelete
  19. Blackbird packaging company can provide you with any size, shape design, and crafted cbd tincture boxes sooner than any other packaging competitor in the market

    ReplyDelete
  20. buy men sweatshirts online from wild goat clothing

    ReplyDelete
  21. lahore grocery
    Shop for Electronic Goods at Al-Fatah, Pakistan's leading chain of departmental stores. Shop from a huge range of top brands Home Appliances, Smart-tech and Phones and Sound bars from Al-Fatah. Shop from huge range of electronics available at Al-Fatah. Avail Free Delivery on orders above 1000 PKR in selected cities.

    ReplyDelete
  22. buy grocery online in lahore from alfatah at best prices. get free shipping

    ReplyDelete
  23. buy online men zipper hoodie from wild goat clothing at best prices. Get Free shipping

    ReplyDelete
  24. buy custom essential oil boxes from blackbird packaging at best prices. Get free shipping.

    ReplyDelete
  25. Buy lawn collection 2021 from Ilaha Clothing at best prices. Get Free shipping.

    ReplyDelete
  26. buy cookie boxes wholesale online from Blackbird Packaging at best prices. Get free shipping

    ReplyDelete
  27. Blackbird packaging company can provide you with any size, shape design, and bath bomb packaging sooner than any other packaging competitor in the market

    ReplyDelete
  28. buy dental care products online from medisense.pk at best prices delivered at your doorstep. get free shipping

    ReplyDelete
  29. buy reflective vest online from Dshred at easy prices delivered at your doorstep. Get free shipping

    ReplyDelete
  30. buy insulins available in pakistan at best prices from medisense delivered at your doorstep. Get free delivery

    ReplyDelete
  31. buy baby care products online from Medisense.pk delivered at your doorstep at best prices. Get free shipping

    ReplyDelete
  32. buy beauty makeup in Pakistan from alfatah at best prices delivered at your doorstep. get free delivery

    ReplyDelete
  33. buy baby products online pakistan online from medisense at best prices deloivered at your doorstep. get free shipping

    ReplyDelete
  34. Buy skin care products in pakistan at easy prices from medisense delivered at your doorstep. Get free shipping.

    ReplyDelete
  35. Buy salazodine ec 500mg online pakistan at easy prices from medisense delivered at your doorstep. Get free shipping.

    ReplyDelete
  36. buy lightweight vest online from dshred at easy prices delivered at your doorstep. get free shipping

    ReplyDelete
  37. The most important things when working out are flexibility and comfort. That is why Dshred has the best collection of Women’s Bottoms and Joggers to suit your needs. We have the best leggings for women and girls in Pakistan. Get high-quality gym trousers and yoga pants for women to suit your workout needs.

    ReplyDelete
  38. buy sports bra online in Pakistan from dshred at easy prices delivered at your doorstep. Get free shipping

    ReplyDelete
  39. buy electronics online from Al-Fatah at best prices delivered at your doorstep. Get free shipping

    ReplyDelete
  40. buy sports bra pakistan online from Dshred at easy prices delivered at your doorstep. Get free shipping

    ReplyDelete
  41. Buy electronics online in Pakistan from Al-Fatah at best prices delivered at your doorstep. Get free shipping

    ReplyDelete
  42. Buy electronics online in pakistan at best prices from Al-Fatah delivered at your doorstep. Get free shipping

    ReplyDelete
  43. From Ndure buy the best quality shorts for men online. Fast Shipping at your doosrstep.

    ReplyDelete
  44. From Ndure buy the best quality sports bra online at affordable price. Fast Shipping.

    ReplyDelete
  45. Buy online grocery in Pakistan at best prices delivered at your doorstep. get free shipping

    ReplyDelete
  46. Thank you, this text could be very useful and interactive for me, in case you promote your USB power you ought to ought to delete your all private statistics and then you definitely ought to overwrite your USB with vain statistics on this manner nobody can get better your private information. for further information about Mobile Homes Movers la

    ReplyDelete
  47. But new afrozeh lawn 2022 online in Pakistan at Highway Fashion. Buy Afrozeh collection Online In Pakistan. Latest collection luxury edition now available.

    ReplyDelete
  48. Keeping a local focus on your website can help you reach out to both local and global customers. Finally, make sure you take full advantage of the ability to interact with current and prospective customers via social media. Not only is this a great way to build stronger relationships but also build a stronger online presence.
    website development Company dubai

    ReplyDelete
  49. ECS is offering best bridal heels which are premium quality product and trendy in design.

    ReplyDelete
  50. Managerial MATLAB assignment help allows students to process the numeric data, which is advanced with Control Engineering

    ReplyDelete
  51. Want To Approach An Affordable Garage Door Cable Repair Arkansas? Feel Free To Call Us, As We Provide You With Professional Services In This Matter. Whether Your Door Is Misaligned, Broken, Or Their Springs Or Cables Are Not Doing Well, We Can Fix It For You.

    ReplyDelete
  52. Buy best and comfortable ladies shoes from dazzle by sarah.

    ReplyDelete
  53. Get ready to shine this Eid with Eid Collection 2023 inspired by the latest fashion trends and modelled by Yumna Zaidi's impeccable style.

    ReplyDelete
  54. Buy Ladies Khussa Shoes Online at best prices.

    ReplyDelete