[BUG] Special Character Causes Queue Message to Fail
See original GitHub issueDescribe the bug When you try to place a message on a queue with a “�” character it causes an exception with the message " XML specified is not syntactically valid."
Expected behavior The character would be escaped and therefore queued and dequeued successfully.
Actual behavior (include Exception or Stack Trace)
The call to place the message onto the queue causes a RequestFailedException
to be thrown. Here is the stack trace:
Azure.RequestFailedException : XML specified is not syntactically valid.
RequestId:cd13cfd1-3a38-4156-9756-75d7d2f1a1e6
Time:2020-04-16T02:00:31.5292245Z
Status: 400 (XML specified is not syntactically valid.)
ErrorCode: InvalidXmlDocument
Additional Information:
LineNumber: 1
LinePosition: 78
Reason: Error parsing Xml content
Headers:
Server: Windows-Azure-Queue/1.0,Microsoft-HTTPAPI/2.0
x-ms-request-id: cd13cfd1-3a38-4156-9756-75d7d2f1a1e6
x-ms-version: 2018-11-09
x-ms-error-code: InvalidXmlDocument
Date: Thu, 16 Apr 2020 02:00:31 GMT
Content-Length: 327
Content-Type: application/xml
at Azure.Storage.Queues.QueueRestClient.Messages.EnqueueAsync_CreateResponse(ClientDiagnostics clientDiagnostics, Response response)
at Azure.Storage.Queues.QueueRestClient.Messages.EnqueueAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri resourceUri, QueueSendMessage message, String version, Nullable`1 visibilitytimeout, Nullable`1 messageTimeToLive, Nullable`1 timeout, String requestId, Boolean async, String operationName, CancellationToken cancellationToken)
at Azure.Storage.Queues.QueueClient.SendMessageInternal(String messageText, Nullable`1 visibilityTimeout, Nullable`1 timeToLive, Boolean async, CancellationToken cancellationToken)
at Azure.Storage.Queues.QueueClient.SendMessageAsync(String messageText, Nullable`1 visibilityTimeout, Nullable`1 timeToLive, CancellationToken cancellationToken)
at Azure.Storage.Queues.QueueClient.SendMessageAsync(String messageText)
at MessageQueueProviderTests.invalid_message()
To Reproduce The following xunit test will trigger the exception (assuming you have the queue “test-queue” in Azure storage emulator):
[Fact]
public async Task invalid_message()
{
var messageText = "String with � character";
var queueClient = new QueueClient("UseDevelopmentStorage=true;", "test-queue");
await queueClient.SendMessageAsync(messageText);
}
Environment:
- Azure.Storage.Queues 12.3.0
- .NET Core SDK 3.1.101
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Special characters appear corrupted when sending m...
Hi,. I am using Power Automate to send messages to an Azure Queue, when certain events are triggered in Dynamics 365.
Read more >Resolving problems when using messages
Solution: Restart the IBM MQ queue manager. The enqueue facility is not picking up changes made to a message. Procedure. Scenario: ...
Read more >Azure Service Bus Queue gives control characters in ...
Turns out it is a .Net application using BrokeredMessage object. Using string makes message serialized, and meta-data is added to the message.
Read more >Error "The request requires a valid JSON body" thrown ...
When publishing a message with a payload that contains special characters, the publishing gets failed due to the error message below. The debug ......
Read more >Known Issues and Limitations (Sun GlassFish Message ...
Known Issues and Limitations. This section contains a list of the known issues with Message Queue 4.4. The following product areas are covered:....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Would be helpful if this was written in the docs somewhere - neither the function signature nor the docs convey this information.
Also from a consumer point of view, wouldn’t it be better if
QueueClient
did the unescaping/escaping? I imagine that a user of this API won’t really care about the underlying format (xml). What’s important is whatever string we pass toSendMessage
will be equal to the string that is returned byReceiveMessage
.I encountered this error today when I sent a message with a
&
. It was puzzling because there was no indication in the API that you need an xml escaped string (and the docs saysThe message content must be a UTF-8 encoded string that is up to 64KB in size.
) but the exception says its invalid xml. It’s not very intuitive.Hi @speedy-ms , This is by design. We expect the message to be a valid xml body message. A quick workaround for you would be to base64 encode the string. Please ack if this works for you.
Thanks