›bobbyencoded_
/posts/newsletter/courses/about
/posts/newsletter/courses/about

The Decode

The week's AI & software news, decoded.

Subscribe →

// © 2026 BobbyEncoded Inc. — A Canadian corporation

← Back to Blog

The Setting That Sent Every Message to the Poison Queue

December 1, 2026 · 7 min read

Azure, Azure Functions, Messaging, C#, Python, Debugging

Here's an Azure gotcha with an unusually clean symptom, and one that's worth knowing before it bites: every message your API puts on a queue ends up in the poison queue, and your function's code never runs. Not once. No exception from your code, no log line from your code, just a growing -poison queue.

The cause is one setting on each side of the queue that doesn't match. It's easy to hit, because both sides are using their documented defaults.

I've been bitten by a cousin of this myself, on Azure Service Bus rather than Storage queues: the sender and the reader disagreed about whether the message body was base64-encoded, so what one side wrote, the other couldn't read. Different service, same root cause, and it's why this Storage queue version caught my eye.

The setup

The shape is common. A web API accepts a request, puts a small JSON message on an Azure Storage queue, and returns. A queue-triggered Azure Function picks the message up and does the slow work. In my example, it resizes an uploaded photo.

// The sender: an API using the Azure.Storage.Queues SDK
var queue = new QueueClient(connectionString, "resize-jobs");
await queue.SendMessageAsync(JsonSerializer.Serialize(job));
// The consumer: an isolated-worker function
[Function(nameof(ResizeImage))]
public void ResizeImage([QueueTrigger("resize-jobs")] ResizeJob job)
{
    // never reached
}

Both look right. Neither is.

The two defaults

  • The Azure Functions host expects base64. The queue extension's host.json setting messageEncoding defaults to base64 (the other valid value is none). The trigger docs say it plainly: "Functions expect a base64 encoded string."
  • The Azure.Storage.Queues SDK sends plain text by default. QueueClientOptions.MessageEncoding defaults to None, so the SDK puts your JSON on the queue exactly as you wrote it. The SDK's own remarks note that base64 "was the default behavior in the prior v11 library", which is why this often shows up right after moving to the v12 SDK.

So the function host takes {"Id":42,...}, tries to base64-decode it before your code ever sees it, and fails. Here's that step on its own, in both languages:

C#

using System.Text;
using System.Text.Json;

var job = new ResizeJob(42, "uploads/beach.jpg", 1080);
string json = JsonSerializer.Serialize(job);

// MessageEncoding.None (the SDK default) puts the text on the queue as-is.
string sentRaw = json;
// MessageEncoding.Base64 encodes it first.
string sentBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(json));

Console.WriteLine($"raw:    {sentRaw}");
Console.WriteLine($"base64: {sentBase64}");
Console.WriteLine();

// A trigger configured with messageEncoding: base64 decodes before your code runs.
foreach (var (label, body) in new[] { ("base64 message", sentBase64), ("raw message", sentRaw) })
{
    try
    {
        string decoded = Encoding.UTF8.GetString(Convert.FromBase64String(body));
        Console.WriteLine($"{label} -> {JsonSerializer.Deserialize<ResizeJob>(decoded)}");
    }
    catch (FormatException ex)
    {
        Console.WriteLine($"{label} -> {ex.GetType().Name}: {ex.Message}");
    }
}

record ResizeJob(int Id, string BlobPath, int Width);
raw:    {"Id":42,"BlobPath":"uploads/beach.jpg","Width":1080}
base64: eyJJZCI6NDIsIkJsb2JQYXRoIjoidXBsb2Fkcy9iZWFjaC5qcGciLCJXaWR0aCI6MTA4MH0=

base64 message -> ResizeJob { Id = 42, BlobPath = uploads/beach.jpg, Width = 1080 }
raw message -> FormatException: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.

Python

import base64
import binascii
import json

job = {"Id": 42, "BlobPath": "uploads/beach.jpg", "Width": 1080}
text = json.dumps(job, separators=(",", ":"))

sent_raw = text                                         # no encode policy
sent_base64 = base64.b64encode(text.encode()).decode()  # TextBase64EncodePolicy

print(f"raw:    {sent_raw}")
print(f"base64: {sent_base64}")
print()

# What a base64-decoding consumer does with each one
for label, body in [("base64 message", sent_base64), ("raw message", sent_raw)]:
    try:
        decoded = base64.b64decode(body, validate=True).decode()
        print(f"{label} -> {json.loads(decoded)}")
    except (binascii.Error, ValueError) as error:
        print(f"{label} -> {type(error).__name__}: {error}")
raw:    {"Id":42,"BlobPath":"uploads/beach.jpg","Width":1080}
base64: eyJJZCI6NDIsIkJsb2JQYXRoIjoidXBsb2Fkcy9iZWFjaC5qcGciLCJXaWR0aCI6MTA4MH0=

base64 message -> {'Id': 42, 'BlobPath': 'uploads/beach.jpg', 'Width': 1080}
raw message -> Error: Only base64 data is allowed

These two programs only reproduce the decoding step locally; they don't talk to Azure.

Why it ends up in the poison queue

A message that fails to process isn't lost. Functions retries it, and per the docs, after five attempts (the maxDequeueCount default) "the functions runtime adds a message to a queue named <originalqueuename>-poison." A decoding failure happens on every attempt, so every message makes the full trip: five tries, then poison.

That's why the symptom is so clean. The failure is in the binding, before your function body, so your own logging never runs. The only clue is the poison queue filling up and the host's own error in the logs. Checking a poisoned message's raw body is the fastest diagnosis: if it's readable JSON instead of base64, this is your bug.

The opposite mismatch fails too. Set messageEncoding to none in host.json while the sender still base64-encodes, and your function receives a base64 string where it expected JSON, so deserialization fails instead.

The fix: match them, in one place

You can fix either side. I prefer leaving the Functions default alone and making the sender match, because host.json applies to every queue binding in the function app, and changing it there can break other functions and senders that already work.

C#

var queue = new QueueClient(connectionString, "resize-jobs",
    new QueueClientOptions { MessageEncoding = QueueMessageEncoding.Base64 });

await queue.SendMessageAsync(JsonSerializer.Serialize(job));

Python

import json
from azure.storage.queue import QueueClient, TextBase64EncodePolicy

queue = QueueClient.from_connection_string(
    conn_str, "resize-jobs", message_encode_policy=TextBase64EncodePolicy()
)
queue.send_message(json.dumps(job))

The more important half of the fix is "in one place." If three services each new up their own QueueClient, one of them will eventually forget the option. Create queue clients through one factory (or one DI registration), so the encoding is decided once:

public static class QueueClients
{
    // Must match "messageEncoding" in the function app's host.json (default: base64).
    public static QueueClientOptions Options() =>
        new() { MessageEncoding = QueueMessageEncoding.Base64 };

    public static QueueClient Create(string connectionString, string queueName) =>
        new(connectionString, queueName, Options());
}

A test that catches it

The cheapest guard is a unit test on that factory, so nobody "simplifies" the option away:

[Fact]
public void Queue_clients_send_base64_to_match_the_functions_host()
{
    Assert.Equal(QueueMessageEncoding.Base64, QueueClients.Options().MessageEncoding);
}

The stronger guard is an integration test against the Azurite storage emulator: send a message through your real sender, peek it with a plain client, and assert the raw body base64-decodes to valid JSON. That catches the bug no matter where the client was created. I haven't included one here because it depends on your test setup, but it's a dozen lines with QueueClient.PeekMessageAsync.

Side note: one serializer on both sides of the queue

A queue is a contract between two programs that may not share code, and the JSON settings are part of that contract. The trap I'd watch for alongside encoding: a sender and a consumer that serialize differently. For example, one side uses Newtonsoft.Json (case-insensitive when reading) and the other uses System.Text.Json (case-sensitive by default), or one side opts into camelCase web defaults and the other doesn't.

Unlike the encoding bug, this one doesn't fail loudly:

using System.Text.Json;

var job = new ResizeJob { Id = 42, BlobPath = "uploads/beach.jpg", Width = 1080 };

// The sender serializes with web defaults (camelCase).
string written = JsonSerializer.Serialize(job, new JsonSerializerOptions(JsonSerializerDefaults.Web));
Console.WriteLine($"on the queue: {written}");

// The consumer reads with plain defaults (case-sensitive, PascalCase).
var read = JsonSerializer.Deserialize<ResizeJob>(written)!;
Console.WriteLine($"consumer got: Id={read.Id}, BlobPath={read.BlobPath ?? "null"}, Width={read.Width}");

class ResizeJob
{
    public int Id { get; set; }
    public string? BlobPath { get; set; }
    public int Width { get; set; }
}
on the queue: {"id":42,"blobPath":"uploads/beach.jpg","width":1080}
consumer got: Id=0, BlobPath=null, Width=0

No exception, just an empty object that your code then processes. My rule now: pick one serializer and one set of options for everything that crosses a queue, put them in a shared place next to the message types, and use them on both sides.

The lesson

Both bugs come from the same thing: two sides of a boundary each using a sensible default, and the defaults not agreeing. The fix in both cases was to stop relying on defaults at the boundary, decide the contract once, and test it. Wire format, encoding and serializer settings are part of a message's schema, even though they never appear in the class.

Further reading

  • Microsoft Learn, Azure Queue storage bindings: host.json settings (messageEncoding, maxDequeueCount)
  • Microsoft Learn, Queue storage trigger: poison messages
  • Azure SDK for .NET, QueueClientOptions.MessageEncoding
  • Azure SDK for Python, TextBase64EncodePolicy
  • Microsoft Learn, Migrate from Newtonsoft.Json to System.Text.Json
  • My Pattern Map post on cloud messaging, for the queue patterns this sits inside
Next →

Claude Wrote the Rust Rewrite in a Week. Proving It Worked Took Five Months.

Thoughts on this?

Tell me on X: @bobbyencoded · Share this post on X

Want more like this? Subscribe to The Decode, a weekly email on the AI and developer news worth your time.