Azure / Azure/azure-functions-dotnet-worker

Not able to bind the data in a servicebus triggered function, .NET 8 isolated model

Open
#3,146 1 comment 0 reactions 0 assignees View on GitHub
enhancement Needs: Triage (Functions)
Dominant language
C#
Stars
466
Forks
215
Avg merge
3d 10h
Merged PRs (30d)
7

Description

### Description

What version of .NET does your existing project use?
.NET 6 In-Process

What version of .NET are you attempting to target?
.NET 8 Isolated

Description
I have a servicebus triggered Azure function in .NET 8 with multiple parameters. Data is not binding automatically.
```

[Function("name")]
public void functionName([ServiceBusTrigger("topic","subscription")] ServiceBusReceivedMessage message,
ICollection lstMyClass, string strData, int intData)
{
// I am able to get the data inside message.Body. But in my lstMyClass, strData and intData are null.
}
```
I've explored several approaches inside custom middleware:

1) Using context.items["strData"]: while I added data here, it didn't auto-bind. I still had to manually deserialize it into a variable, like
strData = JsonConvert.DeserializeObject(context.items["strData"])

2) Populating context.BindingContext.BindingData: I attempted to add strData and its value to context.BindingContext.BindingData. However, the parameter in my ServiceBus trigger function consistently received a null value (Note: adding data to context.BindingContext.BindingData isn't straightforward as it's an abstract class, requiring a custom class inheriting from BindingContext to set values in its constructor).
Interestingly, if a parameter name in my function matches an existing key in context.BindingContext.BindingData (e.g., "Subject"), the data binds correctly. But for custom key-value pairs, I still get null.

3) Modifying context.FunctionDefinition.Parameters: my current, working solution involves updating the defaultValue property of all parameters objects within context.FunctionDefinition with data from serviceBusReceivedMessage.Body. While functional, this doesn't seem like the most optimal implementation.

I have also gone through the documentation and understand that we can bind data as a string, byte[], or ServiceBusReceivedMessage object. and also I can create a model and bind that. But our application is large and has more than 80 functions, so creating models for them isn't the right solution.

As per point 2nd, if matching key with function parameters and context.BindingContext.BindingData, then those keys should auto bind with function parameters.

stack overflow URL:
https://stackoverflow.com/questions/79721281/not-able-to-bind-the-data-in-a-servicebus-triggered-function-net-8-isolated-mo

@jviau Suggested to create a new feature request against old issue #3130.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reviewing the related issue #3130 and the isolated worker binding flow around custom middleware, BindingContext.BindingData, and FunctionDefinition.Parameters. Reproduce the Service Bus trigger example with custom parameters and compare them with existing BindingData keys such as Subject. Done means the intended custom values bind without manually deserializing the message body.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp
Domain
backend, cloud
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.