CloudStorageAccount.Parse fails on trailing semicolon

Be careful not to let a sneaky little semicolon add itself to the end of your Azure connection string!  It’ll cause CloudStorageAccount.Parse to throw “Invalid Account String” exception.  For example

“AccountName=<account>;AccountKey=<key>;DefaultEndpointsProtocol=http”

works as expected, but

“AccountName=<account>;AccountKey=<key>;DefaultEndpointsProtocol=http;

causes the exception.  Spaces after the semicolon result in the exception, too.  The easiest fix is to use TrimEnd

azureConnStr = azureConnStr.TrimEnd(new char[] {‘;’});

I wish Microsoft would code Parse to handle this case more gracefully.  I guess it seems like just a little thing, but when you’re connecting to the cloud tracking down problems like this takes too long.

One thought on “CloudStorageAccount.Parse fails on trailing semicolon”

This site uses Akismet to reduce spam. Learn how your comment data is processed.