remyvd
(Remy van Duijkeren)
November 24, 2021, 4:09am
1
I have created an Azure Function Endpoint in isolated mode. Locally it runs, but when I deploy, I get a binding/conversion error on ‘userProperties’, see below.
Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Functions.NServiceBusFunctionEndpointTrigger-AV.Spotler
---> Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException: Result: Failure
Exception: Microsoft.Azure.Functions.Worker.Diagnostics.Exceptions.FunctionInputConverterException: Error converting 1 input parameters for Function 'NServiceBusFunctionEndpointTrigger-AV.Spotler': Cannot convert input parameter 'userProperties' to type 'System.Collections.Generic.IDictionary`2[[System.String, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]' from type 'System.String'.
at Microsoft.Azure.Functions.Worker.Context.Features.DefaultModelBindingFeature.BindFunctionInput(FunctionContext context) in D:\a\1\s\src\DotNetWorker.Core\Context\Features\DefaultModelBindingFeature.cs:line 70
I have no clue how to fix this. I think this is part of the generated NserviceBus trigger?
NServiceBus.AzureFunctions.Worker.ServiceBus 2.0.1
Microsoft.Azure.Functions.Worker 1.6.0
Microsoft.Azure.Functions.Worker.Sdk 1.3.0
Hi!
We have a fix merged and working on a backport to NServiceBus.AzureFunctions.Worker.ServiceBus 2.0.X
opened 01:36PM - 16 Nov 21 UTC
closed 05:31PM - 17 Nov 21 UTC
bug
### Symptoms
If an exception occurs when processing a message the retry attem… pt fails if using the v4 host.
Exception:
```
System.Private.CoreLib: Exception while executing function: Functions.NServiceBusFunctionEndpointTrigger-ASBWorkerEndpoint. System.Private.CoreLib: Result: Failure
Exception: Microsoft.Azure.Functions.Worker.Diagnostics.Exceptions.FunctionInputConverterException: Error converting 1 input parameters for Function 'NServiceBusFunctionEndpointTrigger-ASBWorkerEndpoint': Cannot convert input parameter 'userProperties' to type 'System.Collections.Generic.IDictionary`2[[System.String, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]' from type 'System.String'.
at Microsoft.Azure.Functions.Worker.Context.Features.DefaultModelBindingFeature.BindFunctionInput(FunctionContext context) in D:\a\1\s\src\DotNetWorker.Core\Context\Features\DefaultModelBindingFeature.cs:line 70
at Microsoft.Azure.Functions.Worker.Invocation.DefaultFunctionExecutor.ExecuteAsync(FunctionContext context) in D:\a\1\s\src\DotNetWorker.Core\Invocation\DefaultFunctionExecutor.cs:line 37
at Microsoft.Azure.Functions.Worker.OutputBindings.OutputBindingsMiddleware.Invoke(FunctionContext context, FunctionExecutionDelegate next) in D:\a\1\s\src\DotNetWorker.Core\OutputBindings\OutputBindingsMiddleware.cs:line 13
at Microsoft.Azure.Functions.Worker.GrpcWorker.InvocationRequestHandlerAsync(InvocationRequest request, IFunctionsApplication application, IInvocationFeaturesFactory invocationFeaturesFactory, ObjectSerializer serializer, IOutputBindingsInfoProvider outputBindingsInfoProvider) in D:\a\1\s\src\DotNetWorker.Grpc\GrpcWorker.cs:line 167
Stack: at Microsoft.Azure.Functions.Worker.Context.Features.DefaultModelBindingFeature.BindFunctionInput(FunctionContext context) in D:\a\1\s\src\DotNetWorker.Core\Context\Features\DefaultModelBindingFeature.cs:line 70
at Microsoft.Azure.Functions.Worker.Invocation.DefaultFunctionExecutor.ExecuteAsync(FunctionContext context) in D:\a\1\s\src\DotNetWorker.Core\Invocation\DefaultFunctionExecutor.cs:line 37
at Microsoft.Azure.Functions.Worker.OutputBindings.OutputBindingsMiddleware.Invoke(FunctionContext context, FunctionExecutionDelegate next) in D:\a\1\s\src\DotNetWorker.Core\OutputBindings\OutputBindingsMiddleware.cs:line 13
at Microsoft.Azure.Functions.Worker.GrpcWorker.InvocationRequestHandlerAsync(InvocationRequest request, IFunctionsApplication application, IInvocationFeaturesFactory invocationFeaturesFactory, ObjectSerializer serializer, IOutputBindingsInfoProvider outputBindingsInfoProvider) in D:\a\1\s\src\DotNetWorker.Grpc\GrpcWorker.cs:line 167.
```
### Who's affected
All users that target the `v4` function host.
### Root cause
The generated code is incorrectly injecting user properties as `IDictionary<string, string>` (should be `IDictionary<string, object>` and while this worked in Host v3 it no longer works when binding occurs after a retry using Host v4
### Backported to
- [2.0.1](https://github.com/Particular/NServiceBus.AzureFunctions.Worker.ServiceBus/pull/84)
## Workaround
You can work around this by implementing your own trigger class like this: (you need to comment out `[assembly:NServiceBusTriggerFunction("{endpointname}")]` to avoid the trigger to be autogenerated)
```
public class FunctionEndpointTrigger
{
IFunctionEndpoint endpoint;
public FunctionEndpointTrigger(IFunctionEndpoint endpoint)
{
this.endpoint = endpoint;
}
[Function("NServiceBusFunctionEndpointTrigger-{endpointname}")]
public async Task Run(
[ServiceBusTrigger("{endpointname}")] byte[] messageBody,
IDictionary<string, object> userProperties,
string messageId,
int deliveryCount,
string replyTo,
string correlationId,
FunctionContext context)
{
await endpoint.Process(messageBody, userProperties.ToDictionary(k => k.Key, k => k.Value.ToString()), messageId, deliveryCount, replyTo, correlationId, context);
}
}
```
in the meantime, you can use the workaround mentioned in the above issue.
Hope this helps!
Andreas
remyvd
(Remy van Duijkeren)
November 26, 2021, 3:17am
3
Hi,
The work around worked and the real error (the reason of the retry) is now visible. Thanks!
btw. this happend on azure function v3.0, not v4.0, in my situtation.
Great news. We’re working on a fix and I’ll report back here once its available.
this happend on azure function v3.0, not v4.0, in my situation.
That is interesting we were not able to reproduce this on v3. Were you able to repro both locally and deployed to azure?
remyvd
(Remy van Duijkeren)
November 28, 2021, 12:03pm
5
I’m not sure that I got the error locally. I must see if I can reproduce this locally.
johnkors
(John Korsnes)
October 22, 2023, 8:02am
6
Just a warning for anyone else:
We got hit by this bug and lead to an infinite loop of invocations the Azure Functions + a huge Azure bill.
Be aware of the NServiceBus defaults when using it together with Azure Functions: https://github.com/Particular/NServiceBus.Transport.AzureServiceBus/blob/a5933e6796b529ad5e95547d7de413f901374821/src/CommandLine/Queue.cs#L12-L19