How to resolve: Microsoft.Azure.WebJobs.Host: Exception binding parameter 'data'. Microsoft.Azure.WebJobs.Host: Object reference not set to an instance of an object

Aaron Manill 86 Reputation points
2022-02-16T23:27:53.193+00:00

I am attempting to locally run my subpub code while testing during development and am running into this error

"System.Private.CoreLib: Exception while executing function: Functions.subpub-trigger-message. Microsoft.Azure.WebJobs.Host: Exception binding parameter 'data'. Microsoft.Azure.WebJobs.Host: Object reference not set to an instance of an object."
when attempting to execute my subpub message trigger with the following code

function.json:
{
"bindings": [
{
"type": "webPubSubTrigger",
"direction": "in",
"name": "data",
"hub": "simplechat",
"eventName": "message",
"eventType": "user"
},
{
"type": "webPubSub",
"name": "actions",
"hub": "simplechat",
"direction": "out"
}
]
}

index.js:

module.exports = async function (context, data) {  
    context.bindings.actions = {  
        "actionName": "sendToAll",  
        "data": `[${context.bindingData.request.connectionContext.userId}] ${data}`,  
        "dataType": context.bindingData.dataType  
    };  
    // UserEventResponse directly return to caller  
    var response = {   
        "data": '[SYSTEM] ack.',  
        "dataType" : "text"  
    };  
    return response;  
};  

The code is actually taken directly from this tutorial: https://learn.microsoft.com/en-us/azure/azure-web-pubsub/quickstart-serverless?tabs=javascript

Azure Web PubSub
Azure Web PubSub
An Azure service that provides real-time messaging for web applications using WebSockets and the publish-subscribe pattern.
75 questions
{count} votes

Accepted answer
  1. Ryan Hill 28,286 Reputation points Microsoft Employee
    2022-02-19T01:48:19.58+00:00

    @Aaron Manill , I couldn't get this quick start to work locally with ngrok. I used the Live Trace Tool and kept hitting AbuseProtectionResponseMissingAllowedOrigin followed by web socket connection closing. Not sure if had anything to do with https://github.com/MicrosoftDocs/azure-docs/issues/86799, but after deploying the application to an Azure Function app, it worked as expected.

    175980-image.png

    See if you get the same error when deployed, that will confirm if it's a configuration error or not. Could be a misconfiguration on the hub event handler settings, or it could be an issue with the reverse proxy you're using. Since you are getting the web pubsub trigger to fire locally, try adding --verbose to func host start or using fiddler to get a closer look at the traffic going across the web socket. Might be a malformation in the payload itself.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.