6

I am trying to simply create a new Storage Queue with Azure but it keeps crash without explanation, creating tables worked just fine, this is the relevant code:

        private CloudTable userTable;
        private CloudTable petTable;
        private CloudQueue healingQueue;

        public override bool OnStart()
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("connectionString"));
            CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
            userTable = tableClient.GetTableReference("users");
            userTable.CreateIfNotExists();
            petTable = tableClient.GetTableReference("pets");
            petTable.CreateIfNotExists();

            // This is where I create the queue: //
            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
            healingQueue = queueClient.GetQueueReference("healQueue");
            healingQueue.CreateIfNotExists(); // This line makes the code crash.
        }

Code crashes in line healingQueue.CreateIfNotExists(); with the explanation of (400) bad request

Tables are created just fine so I assume there is no problem with the storage account, any ideas what I can do?

Guy Ben-Moshe
  • 874
  • 1
  • 15
  • 23

1 Answers1

24

The problem is in the following line of code:

healingQueue = queueClient.GetQueueReference("healQueue");

Essentially the reason you're getting this error is because you are choosing an invalid name for a queue. Try using healqueue (all lowercase).

Please see this link for Queue naming rules: https://msdn.microsoft.com/en-us/library/azure/dd179349.aspx.

Gaurav Mantri
  • 128,066
  • 12
  • 206
  • 241
  • 2
    Even if I worked on this piece of code for a milion years I would never think of that, so far Azure is beyond frustrating (The server could return something like "upper case characters are not allowed" instead of "bad request"). Anyway thanks a lot, you saved me a lot of troubles! – Guy Ben-Moshe Jan 16 '16 at 11:11
  • 2
    I agree with you that error messages can be more descriptive. As you play more with Azure, if you get 400 error back from storage service, look for names, data types and values. For example, check out this thread: http://stackoverflow.com/questions/14859405/azure-table-storage-returns-400-bad-request/ – Gaurav Mantri Jan 16 '16 at 11:15
  • Would never have figured this out without your answer. a million +1s to you! – Code Magician Jun 09 '17 at 02:52
  • Just to add to that, an easy way to handle it is to use `NameValidator` provided by the sdk -> https://github.com/Azure/azure-storage-net/blob/3187d0f14d78fbb060dcbc9e7be6aee8a36b3532/Lib/Common/NameValidator.cs#L59 – Daniel Dror Jan 10 '19 at 10:45
  • If you try to use CloudQueue.GetMessagesAsync(int batchSize ...) with a batchSize greater than 32 you also get 400 Bad Request back. Thought it was worth mentioning because Google directed me here in my search for answers. – RichyRoo May 29 '19 at 06:20