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

58 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
  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. Online gaming is a hobby of many people. Game Run Unblockedversions as Run 3 Unblocked or Run 4 Unblocked is a very interesting game to control the bear run or jump to the safe landing area falls. risks with such racing game Car Racing Games or interesting as the game Donkey Kong Unblocked or Car Racing Games wrap pulled a lot of players. Good luck!

    ReplyDelete
  4. With football we always have exciting games such as head soccer and head soccer unblocked and soccer heads and head soccer 2 or big head basketball big head soccer or head soccer will bring to everyone the good entertainment Best. After work you can play with Big Head Football and Big Head Soccer or Head Soccer to reduce the pressure of work. With big head basketball

    ReplyDelete
  5. Head Soccer and Big Head Football you will have the best experience on the sport king. big head basketball and Head Soccer and Big Head Soccer and Big Head Football will make the most demanding on electronic games must also satisfied. Come to Big Head Football and big head basketball and Big Head Soccer to experience the most wonderful thing. Thank you.

    ReplyDelete
  6. 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
  7. Here we present to introduce to all visitors in this great blog. and thank you for allowing me . cara menggugurkan kandungan

    ReplyDelete
  8. This is a very good article material and it is very useful for us all. thank you . cara menggugurkan kandungan

    ReplyDelete
  9. 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
  10. 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
  11. 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
  12. Buy Premium lawn Online for Women's at best prices available at Motifz. ✓ Latest Fashion, ✓ Trendy Designs ➤ Shop Now!

    ReplyDelete
  13. This is really unbelievable and extraordinary work. Everyone should read. Thanks for sharing and don't miss WORLD'S BEST

    MonsterTrucks

    ReplyDelete
  14. Hey,

    Thenkx For Sharing this article for us. this is really cool.
    Thenkx again

    Regards
    ChaluBaba

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

    ReplyDelete
  16. 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
  17. Wholesale printed custom perfume boxes with the highest quality and affordable prices. Free worldwide Delivery and free Custom Perfume Boxes design.

    ReplyDelete
  18. 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
  19. Buy online wholesale lipstick boxes and packaging at seashore packaging at the easy price Free shipping worldwide with 24/7 customer support.

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

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

    ReplyDelete
  22. mylar label bags in stock now. Ready made Cali pack designs. Fast Shipping at Your Supplies. Custom designs available

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

    ReplyDelete
  24. Great Article
    Cloud Computing Projects




    Networking Projects



    Final Year

    Projects for CSE





    JavaScript Training in Chennai



    JavaScript

    Training in Chennai




    The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals,

    Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer.

    Angular Training

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

    ReplyDelete
  26. 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
  27. cali spliff 3.5g Direct Print on the front and back. % Cali Packs Available at Your Supplies. Heat sealable mylar bags. Fast Shipping.

    ReplyDelete
  28. Blackbird packaging provide you with any size, shape design, custom pet food packaging sooner than any other packaging competitor in the market

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

    ReplyDelete
  30. Blackbird packaging provide you with any size, shape design, custom wholesale cookie boxes sooner than any other packaging competitor in the market

    ReplyDelete
  31. 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
  32. Packaging town is a one stop solution for the short-run custom pillow boxes needs and supplies. At affordable prices. Request a free quote now.

    ReplyDelete
  33. 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
  34. buy grocery online in lahore from alfatah at best prices. get free shipping

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

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

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

    ReplyDelete
  38. Hello, My Dearest Friends Super class independent Escorts Services available incall & outcall
    service in VIP hotels.and call girls available for booking 24x7 hours IF You
    want Physical Relationship any time contact me & ?meet with me to get my
    number from website and call
    Thank You & Visit Again""_____
    Guwahati Call Girls
    Call Girls in Guwahati

    ReplyDelete
  39. Hello, This is a Nitu roy very interesting blog. this content is written very well This is an amazing
    post, keep blogging.thanks for sharing.Anyways I am here now and could just like to say thank
    for a tremendous post and a all round entertaining website.
    Guwahati Escort
    Call girl service in Guwahati

    ReplyDelete
  40. Maybe you are also looking for the right person to ensure the higher quality
    sex and that’s why you are in this place because here we are going to share
    the data and information of Guwahati Escorts.
    Guwahati escorts
    Escorts in Guwahati

    ReplyDelete
  41. Explore the profiles of guwahati escorts, guwahati call girls, call girls in guwahati and
    escorts in guwahati for female companionship in top rated hotels.
    Get affordable escort services in guwahati hotels now.
    Guwahati call girl
    Guwahati escort service

    ReplyDelete
  42. Very nicely written blog...Relly loved reading it...Please check my blogs for
    Bhubaneswar escort
    Call girl in Bhubaneswar

    ReplyDelete
  43. Shop from a wide range of Local and Imported variety of makeup removers and makeup remover wipes from Al-Fatah. Shop from a diversified range of makeup removers and makeup remover wipes from all top brands. Buy the best for your skin. Avail Free Delivery on orders above 1000 PKR for selected cities in Pakistan.

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

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

    ReplyDelete
  46. Blackbird packaging company can provide you with any size, shape design, and wholesale cookie boxes sooner than any other packaging competitor in the market

    ReplyDelete
  47. Packaging town is a one stop solution for the short-run business card boxes wholesale needs and supplies. At affordable prices. Request a free quote now.

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

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

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

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

    ReplyDelete