I'm creating an Azure Function with Service Bus trigger and trying to bind the incoming message to a custom class of mine:
public class InputMessage
{
public string EntityId { get; set; }
}
public static string Run(InputMessage message, TraceWriter log)
{
log.Info($"C# ServiceBus trigger function processed message: {message}");
}
My message is JSON, e.g.
{ "EntityId": "1234" }
Unfortunately, the binding fails at runtime with the following message:
Exception while executing function: Functions.ServiceBusTriggerCSharp1. Microsoft.Azure.WebJobs.Host: One or more errors occurred. Exception binding parameter 'message'. System.Runtime.Serialization: Expecting element 'Submission_x0023_0.InputMessage' from namespace 'http://schemas.datacontract.org/2004/07/'.. Encountered 'Element' with name 'string', namespace 'http://schemas.microsoft.com/2003/10/Serialization/'. .
It looks like the runtime tries to deserialize the message with DataContractSerializer
. How do I switch the deserialization to JSON?