I'm getting the error message "Cannot convert input parameter" when trying to use my service bus triggered function, why?
Asked Answered
H

2

6

Is there a way to create azure function that will expect object of ServiceBusReceivedMessage as parameter? like this:

[Function("Function1")]
public static void Run(
    [ServiceBusTrigger("...", "...", Connection = "...")] ServiceBusReceivedMessage  msg)

I have some extension methods created for this class so it would be useful for me to use this class.

I've notice this tutorial Azure Service Bus bindings for Azure Functions

I'm using .net 5 and I've installed via nuget package Microsoft.Azure.WebJobs.Extensions.ServiceBus with beta-5 version but when I try to receive a message i see this error:

Exception: Microsoft.Azure.Functions.Worker.Diagnostics.Exceptions.FunctionInputConverterException: Error converting 1 input parameters for Function 'Function1': Cannot convert input parameter 'msg' to type 'Azure.Messaging.ServiceBus.ServiceBusReceivedMessage' from type 'System.String'.

not sure if I miss something or if it's possible at all

Helminthiasis answered 20/7, 2021 at 11:47 Comment(0)
K
0

Microsoft.Azure.WebJobs.Extensions.ServiceBus version 5 is intended to work with in-process Functions SDK. Your solution seems to use Functions isolated worker SDK, which doesn't support SDK types as of now.

Kipp answered 20/7, 2021 at 13:37 Comment(10)
hey, thank you for your answer, can you please guide me what/where I need to change to have this working? I'm new in azure functions and don't know what to do next.Helminthiasis
You need to change your Functions SDK to the in-process SDK, Microsoft.NET.Sdk.Functions and read/follow documentation/tutorials that are intended for the correct SDK.Kipp
@SeanFeldman I feel like for isolated functions the ServiceBus binding to a SB type like ServiceBusReceivedMessage should be offered in the binding extensions no?Jacquline
Isolated worker SDK doesn't provide support for native SDK types such as ServiceBusReceivedMessage as of today.Kipp
@SeanFeldman, yes I agree that is true. What I'm asking is, isn't that a great role for the extensions to fill if users should want to get those types in the isolated model?Jacquline
The current design of the Isolated worker SDK doesn't allow it, unfortunately. Has to do with the assembly version conflicting the team was trying to solve.Kipp
@SeanFeldman Is there any way around this that's been surfaced since Feb? I'm running into the same issue...was hoping to use isolated function in .net6 ... I'm using Microsoft.Azure.Functions.Worker.Sdk. thanks.Ledoux
Not that I know of. Untill Isolated Worker SDK doesn't add some sort of support or abstraction, this will remain the case. You can upvote the issue on GitHub if you want to vote for this feature.Kipp
Thanks. Any guidance as to why the following code doesn't work (using Newtonsoft)? It'll create the SBReceivedMessage object, but it's empty.. var data = JsonConvert.DeserializeObject<ServiceBusReceivedMessage>(message.ToString());Ledoux
ServiceBusReceivedMessage is a bit more than just a POCO. Trying to deserialize it from a string won't work as you expect. Instead, you should deserialize your message to a POCO you expect to work with or use Functions In-Process SDK if you need to have an SDK message type. If none helps, perhaps raise a separate question that formulates what you're attempting with more details.Kipp
P
0

I'm a little late to this thread and have just run into this problem also.

For me, the right solution was to change the ServiceBusReceivedMessage to ServiceBusReceivedMessage[] and set "IsBatched = true" on the ServiceBusTrigger

Yeah, it's a tiny change, but I overlooked it for a good few hours!

enter image description here

Pictish answered 21/10, 2024 at 15:46 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.