Azure / azure-functions-dotnet-worker

Azure Functions out-of-process .NET language worker
MIT License
418 stars 182 forks source link

ServiceBusOutput does not support byte[] as claimed #2547

Open tyrielv opened 3 months ago

tyrielv commented 3 months ago

Description

The documentation says that [ServiceBusOutput] supports returning byte[], string, or an object which will be serialized as JSON.

When I specify return type as byte[] and return a byte[], the message body that results is the literal string "System.Byte[]" - as if the framework is calling ToString() on the byte array.

Steps to reproduce

[Function(nameof(ForwardToQueue))]
[ServiceBusOutput("OutputQueueName", Connection = "Connection")]
public byte[] ForwardToQueue(
    [ServiceBusTrigger("InputQueueName", Connection = "Connection")]byte[] message)
{
    return message;
}

Expected: The function forwards a message with the same body to another queue. Actual: The function creates a message with the literal body "System.Byte[]"

Microsoft.Azure.Functions.Worker.Sdk 1.17.2 Microsoft.Azure.Functions.Worker.Extensions.ServiceBus 5.20.0

.NET 6 isolated

kshyju commented 3 months ago

Thanks for reporting. We will investigate and share an update. Until then, you may consider returning a string instead of byte array to unblock yourself.

[Function(nameof(ForwardToQueue))]
[ServiceBusOutput("OutputQueueName", Connection = "Connection")]
public string ForwardToQueue(
    [ServiceBusTrigger("InputQueueName", Connection = "Connection")]byte[] message)
{
    return System.Text.Encoding.UTF8.GetString(message);
}