Azure/azure-functions-dotnet-worker

Secondary Object Passed To Function Definition Is Null or Empty

derinsola01 opened this issue · 2 comments

Description

I upgraded my azure functions project from .NET6 to .NET8 and Objects that worked no longer work like in the example below.

using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.WebJobs;

[Function(nameof(functionName))]
public async Task<string> Run([ActivityTrigger] string thisWorks, Binder binder)
{
        using (var writer = await binder.BindAsync<TextWriter>(attributes).ConfigureAwait(false))
        {
            writer.WriteLine(" ");
            foreach (var batchItem in someList)
            {
                writer.WriteLine(batchItem);
            }
        }
}

The Binder object is now null. I noticed that every Object I passed into the function that doesn't have a binding [BINDING_OBJECT], returned null and was unusable in the code. Is there a way to pass parameters successfully without having the objects be null?

Steps to reproduce

The snippet I provided will fail in .NET8 isolated worker code. It worked well with the in-process code of .NET6.

I will appreciate a code sample of how to rewrite my piece of code.

Populating the Microsoft.Azure.WebJobs.Binder instance is currently not supported in the dotnet isolated model.

But you can bind your inputs using the BindInputAsync method to bind an input. This is useful when you want to get the input binding data in another layer such as middleware, which the isolated model supports.

https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.functions.worker.functioncontextbindingfeatureextensions.bindinputasync?view=azure-dotnet

Can you share more information/relevant code about what data you were trying to bind to? We can take a look and advice.

Thanks @kshyju, I found a fix to my issue. I used BlobContaineerClient and it did the trick. Thanks