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.
You 'Bitch and moan', so that I didn't have to!
ReplyDeleteThanks :-)
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.
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.
ReplyDeleteOnline 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!
ReplyDeleteWith 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
ReplyDeleteHead 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.
ReplyDeleteCreating 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
ReplyDeleteHere we present to introduce to all visitors in this great blog. and thank you for allowing me . cara menggugurkan kandungan
ReplyDeleteThis is a very good article material and it is very useful for us all. thank you . cara menggugurkan kandungan
ReplyDeletePest Control services in Kirti Nagar
ReplyDeletePest Control services in Modi Nagar
Pest Control services in Patel Nagar
Pest Control services in Rajouri Garden
Pest Control services in Tilak Nagar
Pest Control services in Janakpuri
Pest Control services in Paschim Vihar
Awesome post about also check it Blog!Mobilism for android simcity buildit mod android download dead trigger mod apk
ReplyDeleteIndia's only Digital News Channel with True Voice of India.
ReplyDeleteFinding #Championsofchange2018 #rahulshivkant
the universal post teams
the universal post youtube
loksabha election 2018
top trending news
top viral news
best trending news in india
Prospectus Patrachar Vidyalaya
ReplyDeleteCBSE Forms
CBSE Patrachar Delhi
Patrachar Vidyalaya phone no.
packer and mover chandigarh
Packers and movers in panchkula
packers and movers in mohali
nice post friend , Thank you for sharing with us, and we sincerely hope you will continue to update or post other articles
ReplyDeletemutilateadoll23.com
luffygames.com
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.
ReplyDeleteMotifz 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.
ReplyDeleteBuy Premium lawn Online for Women's at best prices available at Motifz. ✓ Latest Fashion, ✓ Trendy Designs ➤ Shop Now!
ReplyDelete