XmlException: Root element is missing while performing PUT operation
Published Jul 26 2019 02:53 AM 5,226 Views
Microsoft

Scenario:

While invoking a REST API to perform PUT message to add a message to the Azure Queue storage, I was getting the below exception:

 

 

Microsoft.WindowsAzure.Storage.StorageException occurred

HResult=0x80131500

Message=Root element is missing.

Source=<Cannot evaluate the exception source>

StackTrace:

   at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd,

     IRetryPolicy policy, OperationContext operationContext)

   at Microsoft.WindowsAzure.Storage.Queue.CloudQueue.AddMessage(CloudQueueMessage message, Nullable`1

     timeToLive, Nullable`1 initialVisibilityDelay, QueueRequestOptions options, OperationContext

     operationContext)

   at QueueSASSender.Program.Main(String[] args) in E:\Cxfiles\117092716404612\2017-11-

     03\QueueSASSender\QueueSASSender\Program.cs:line 41

 

Inner Exception 1:

XmlException: Root element is missing.

 

 

My sample code was as shown below:

 

 

var queueClient =   new CloudQueueClient(new Uri("https://*****.queue.core.windows.net:443/"),

                   new StorageCredentials("?st=2018-11-27T23%3A22%3A00Z&se=2020-12-

                   30T23%3A22%3A00Z&sp=raup&sv=2012-02-                

                   12&sig=VBzLT2lPg7********************%2BI%3D"));

 

var queue = queueClient.GetQueueReference("myqueue");

queue.AddMessage(new CloudQueueMessage("my message"));

 

 

Cause:

I started my investigation with the SAS Token which was in the below format:

sv=2012-02-12&si=****&sig=cD7NF1cCra01Wj8mIid%*********gOVA9VVsbQg%3D

 

The one that grabbed my attention was ‘sv’ (Service Version). I could see that I was using an older version to formulate the token (sv=2012-02-12).

 

I tried to compose the request again and confirmed if that was indeed the cause of this issue. I created a new SAS token using a different version of the sv (Service Version), though not the most recent one.

 

Below is my new SAS token:

st=2018-11-27T23%3A22%3A00Z&se=2020-12-30T23%3A22%3A00Z&sp=raup&sv=2017-04-17&sig=VBzLT2lPg7jwT5***********%2BI%3D

 

Resolution:

I have referred to the document which says the new SDK is expecting the Put Message API call to return a valid XML response. Since the SAS signature had an older version no response was returned from the Azure Queue Storage.

 

Capture.PNG

 

Also note that the message was getting added in the queue though we got the exception in the response. A workaround may be to simply ignore the storage exception generated by this API, but this carries risk as you may be ignoring genuine exceptions too.

 

We strongly recommend that you regenerate the SAS signature to allow you to take advantage of all the features that have been added over the years to the Azure Storage SDK.

 

Hope this helps.

 

:smiling_face_with_smiling_eyes:

Version history
Last update:
‎Jul 30 2019 10:19 PM
Updated by: