0

I have a storage queue to which I post messages constructed using the CloudQueueMessage(byte[]) constructor. I then tried to process the messages in a webjob function with the following signature:

public static void ConsolidateDomainAuditItem([QueueTrigger("foo")] CloudQueueMessage msg)

I get a consistent failure with exception

Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Program.ConsolidateDomainAuditItem ---> System.InvalidOperationException: Exception binding parameter 'msg' ---> System.Text.DecoderFallbackException: Unable to translate bytes [FF] at index -1 from specified code page to Unicode.
 at System.Text.DecoderExceptionFallbackBuffer.Throw(Byte[] bytesUnknown, Int32 index)
 at System.Text.DecoderExceptionFallbackBuffer.Fallback(Byte[] bytesUnknown, Int32 index)
 at System.Text.DecoderFallbackBuffer.InternalFallback(Byte[] bytes, Byte* pBytes)
 at System.Text.UTF8Encoding.GetCharCount(Byte* bytes, Int32 count, DecoderNLS baseDecoder)
 at System.String.CreateStringFromEncoding(Byte* bytes, Int32 byteLength, Encoding encoding)
 at System.Text.UTF8Encoding.GetString(Byte[] bytes, Int32 index, Int32 count)
 at Microsoft.WindowsAzure.Storage.Queue.CloudQueueMessage.get_AsString()
 at Microsoft.Azure.WebJobs.Host.Storage.Queue.StorageQueueMessage.get_AsString()
 at Microsoft.Azure.WebJobs.Host.Queues.Triggers.UserTypeArgumentBindingProvider.UserTypeArgumentBinding.BindAsync(IStorageQueueMessage value, ValueBindingContext context)
 at Microsoft.Azure.WebJobs.Host.Queues.Triggers.QueueTriggerBinding.<BindAsync>d__0.MoveNext()

Looking at the code of UserTypeArgumentBindingProvider.BindAsync, it clearly expects to be passed a message whose body is a JSON object. And the UserType... of the name also implies that it expects to bind a POCO.

Yet the MSDN article How to use Azure queue storage with the WebJobs SDK clearly states that

You can use QueueTrigger with the following types:

  • string
  • A POCO type serialized as JSON
  • byte[]
  • CloudQueueMessage

So why is it not binding to my message?

Peter Taylor
  • 4,918
  • 1
  • 34
  • 59

2 Answers2

0

The WebJobs SDK parameter binding relies heavily on magic parameter names. Although [QueueTrigger(...)] string seems to permit any parameter name (and the MSDN article includes as examples logMessage, inputText, queueMessage, blobName), [QueueTrigger(...)] CloudQueueMessage requires that the parameter be named message. Changing the name of the parameter from msg to message fixes the binding.

Unfortunately, I'm not aware of any documentation which states this explicitly.

Peter Taylor
  • 4,918
  • 1
  • 34
  • 59
  • 1
    The name of the parameter doesn't factor into the binding logic at all - you can name it whatever you want. Perhaps some other change occurred that made your function start working? It can't be the parameter name :) – mathewc May 18 '16 at 03:05
0

Try this instead:

public static void ConsolidateDomainAuditItem([QueueTrigger("foo")] byte[] message)

CloudQueueMessage is a wrapper, usually the bindings get rid of the wrapper and allow you to deal with the content instead.

user1075679
  • 287
  • 1
  • 2
  • 13