I was using .net core Azure function in an app, with no problem faced, with the below code.
But when I create an Azure function app using .net framework it is throwing below error.
I tried all possible google solutions. the error is clearly because of nuget and library as same code works fine for v2 .net core function app.
[FunctionName("Function1")]
public static async System.Threading.Tasks.Task RunAsync([ServiceBusTrigger("topic", "sub", Connection = "ConnectionStringSettingName")]Message mySbMsg, string lockToken, MessageReceiver messageReceiver, ILogger log)
{
log.LogInformation($"C# ServiceBus topic trigger function processed message: {mySbMsg}");
}
I even tried this as well:
[FunctionName("Function1")]
public static async System.Threading.Tasks.Task RunAsync([ServiceBusTrigger("topic", "sub", Connection = "ConnectionStringSettingName")]Message mySbMsg, Guid lockToken, MessageReceiver messageReceiver, ILogger log)
{
log.LogInformation($"C# ServiceBus topic trigger function processed message: {mySbMsg}");
}
If I took it as guid or string or vice versa, it gives the error:
Error indexing method 'Function1.RunAsync'.
Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'lockToken' to
type Guid. Make sure the parameter Type is supported by the binding.
If you're using binding extensions (e.g. ServiceBus, Timers, etc.)
make sure you've called the registration method for the extension(s)
in your startup code (e.g. config.UseServiceBus(), config.UseTimers(),
etc.).
Vice versa error:
RunAsync: Microsoft.Azure.WebJobs.Host: Error indexing method
'Function1.RunAsync'. Microsoft.Azure.WebJobs.Host: Cannot bind
parameter 'lockToken' to type Guid. Make sure the parameter Type is
supported by the binding. If you're using binding extensions (e.g.
ServiceBus, Timers, etc.) make sure you've called the registration
method for the extension(s) in your startup code (e.g.
config.UseServiceBus(), config.UseTimers(), etc.).
The locktoken parameter that you are sending in is a string.
The error message is that it cannot bind the locktoken to a Guid.
Therefore, it is probably expecting a string that is a valid Guid, and you are sending in something else.
Related
I've created a simple Azure function which is triggered on a service bus queue.
I'd like to inject a the full message payload into the trigger. Now there are 2 libraries available for working with Azure Service Bus - the older https://www.nuget.org/packages/Microsoft.Azure.ServiceBus/ and the newer https://www.nuget.org/packages/Azure.Messaging.ServiceBus/
If I inject in the message payload using Microsoft.Azure.ServiceBus.Message works, however using the newer Azure.Messaging.ServiceBus.ServiceBusMessage gives a run-time error.
Ideally would like to use the newer library - is there any config change required to make this work?
The error is
Executed 'IncomingMessageProcessingFunction' (Failed, Id=01b3f0c1-fe4d-4d0f-89db-7814a4a0ddbe, Duration=2756ms)
[2021-09-13T10:56:47.944Z] System.Private.CoreLib: Exception while executing function: IncomingMessageProcessingFunction. Microsoft.Azure.WebJobs.Host: Exception binding parameter 'myQueueItem'. Microsoft.Azure.WebJobs.ServiceBus: Binding parameters to complex objects (such as 'ServiceBusMessage') uses Json.NET serialization or XML object serialization.
[2021-09-13T10:56:47.946Z] 1. If ContentType is 'application/json' deserialize as JSON
[2021-09-13T10:56:47.948Z] 2. If ContentType is not 'application/json' attempt to deserialize using Message.GetBody, which will handle cases like XML object serialization
[2021-09-13T10:56:47.949Z] 3. If this deserialization fails, do a final attempt at JSON deserialization to catch cases where the content type might be incorrect
[2021-09-13T10:56:47.951Z] The JSON parser failed: Error converting value 123 to type 'Azure.Messaging.ServiceBus.ServiceBusMessage'. Path '', line 1, position 3.
Works
[FunctionName("IncomingMessageProcessingFunction")]
public static void Run([ServiceBusTrigger("incomingmessageprocessingqueue", Connection = "SERVICEBUS")]Microsoft.Azure.ServiceBus.Message myQueueItem, ILogger log)
{
log.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem.Body}");
I'm developing a Service Bus Trigger in Azure Functions v1 locally with Visual Studio 2017. I want to test the example from the official docs without having to put a message in the service bus. So I trigger it via Postman at endpoint POST http://localhost:7071/admin/functions/ServiceBusQueueTriggerCSharp with body { "input": "foo" }.
This fails with a script host error: Exception while executing function: ServiceBusQueueTriggerCSharp. Microsoft.Azure.WebJobs.Host: One or more errors occurred. Exception binding parameter 'deliveryCount'. Microsoft.Azure.WebJobs.Host: Binding data does not contain expected value 'deliveryCount'.
I tried removing the deliveryCount argument, but then it fails at enqueueTimeUtc. Removing that too works. Is there a way to keep these arguments and test the Function locally?
I understand that these two arguments wouldn't make much sense when triggered via HTTP, but they could be given default values. messageId has a non-zero value.
Example for reference:
[FunctionName("ServiceBusQueueTriggerCSharp")]
public static void Run(
[ServiceBusTrigger("myqueue", AccessRights.Manage, Connection = "ServiceBusConnection")]
string myQueueItem,
Int32 deliveryCount, // this fails
DateTime enqueuedTimeUtc, // this fails too
string messageId,
TraceWriter log)
{
log.Info($"C# ServiceBus queue trigger function processed message: {myQueueItem}");
log.Info($"EnqueuedTimeUtc={enqueuedTimeUtc}");
log.Info($"DeliveryCount={deliveryCount}");
log.Info($"MessageId={messageId}");
}
As of right now, if you want to be able to work with these additional metadata properties, you'll need to use a real service bus message.
In theory, the admin endpoint could be smart enough to allow you to pass additional binding data (such as deliveryCount in this case) as query parameters. I filed the following feature request to track:
https://github.com/Azure/azure-functions-host/issues/2955
When creating a new QueueTrigger Azure function, I'd like to switch the string input to a CloudQueueMessage.
I have changed the signature to:
public async static Task Run([QueueTrigger("%queue-name%", Connection = "AzureStorageConnection")]CloudQueueMessage myQueueItem, TraceWriter log)
I get the error below:
8/15/17 12:16:07 AM] Function started (Id=a137d868-1256-4a67-a225-8a95fb0e31fb)
[8/15/17 12:16:07 AM] Executing 'TokenRefresh' (Reason='New queue message detected on 'refreshtoken'.', Id=a137d868-1256-4a67-a225-8a95fb0e31fb)
[8/15/17 12:16:07 AM] A ScriptHost error has occurred
[8/15/17 12:16:07 AM] Exception while executing function: TokenRefresh. Microsoft.Azure.WebJobs.Host: Exception binding parameter 'myQueueItem'. mscorlib: String reference not set to an instance of a String.
[8/15/17 12:16:07 AM] Parameter name: s.
The function app is correctly popping items and then then because it is then throwing rapid exceptions all items in that queue go to the poison queue. I'm using the latest functions sdk and windows azure sdk nuget packages.
According to your description, I checked this issue on Azure portal. I found it could work, and here is the code snippet under my run.csx file as follows:
#r "Microsoft.WindowsAzure.Storage"
using System;
using Microsoft.WindowsAzure.Storage.Queue;
[FunctionName("QueueTriggerCSharp")]
public static void Run([QueueTrigger("myqueue-items", Connection = "AzureWebJobsStorage")]CloudQueueMessage myQueueItem, TraceWriter log)
{
log.Info($"C# Queue trigger function processed: {myQueueItem.AsString}");
}
Result:
2017-08-15T07:35:27.104 Function started (Id=0ed03b74-bc9c-408a-9607-55e2942f1d50)
2017-08-15T07:35:27.214 C# Queue trigger function processed: sample queue data
2017-08-15T07:35:27.214 Function completed (Success, Id=0ed03b74-bc9c-408a-9607-55e2942f1d50, Duration=108ms)
As garth mason mentioned, then I checked it on my local side by using VS 2017 function class library. Also, I found a similar issue How to change the parameters types using a queue trigger and a VS 2017 function class library and this git issue, you could refer to them for solving this issue.
It turns out that this was a result of trying to use Windows.AzureStorage v8.2.1 instead of the v7.2.1 which is binding redirected. Since the CloudQueueMessage object is a mismatch between versions, you have to use the dependencies that Functions runtime depends on.
Confirmed by Functions PM:
https://twitter.com/lindydonna/status/897333107354869760
And also a lengthy issue thread here on the state of things for when they'll allow other dependency versions:
https://github.com/Azure/azure-webjobs-sdk-script/issues/992
I have a Queue Trigger in Azure function Function, Right now it has method signature as :
Run([QueueTrigger("listner")]string myQueueItem, TraceWriter log)
I want to add one more parameter of type CloudQueueMessage. So when i added it. it throws an error like Message ->
(QueueTriggerForFileProcessing) Error: Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.QueueTriggerForFileProcessing'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'msg' to type CloudQueueMessage. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).
Does anyone come across similar requirement ? any workable solution to this?
Thanks in advance
Ravi
Please ensure you're targeting the same storage package version as what the storage binding currently uses (currently, 7.2.1).
You can use different versions if using those types from within your function (not relying on bindings), but when binding to types from the package, you'll need to use the version expected by the runtime.
Trying to get Azure Webjobs to react to incoming Service Bus event, Im running this by hitting F5. Im getting the error at startup.
No job functions found. Try making your job classes and methods
public. If you're using binding extensions (e.g. ServiceBus, Timers,
etc.) make sure you've called the registration method for the
extension(s) in your startup code (e.g. config.UseServiceBus(),
config.UseTimers(), etc.).
My functions-class look like this:
public class Functions
{
// This function will get triggered/executed when a new message is written
// on an Azure Queue called queue.
public static void ProcessQueueMessage([ServiceBusTrigger("test-from-dynamics-queue")] BrokeredMessage message, TextWriter log)
{
log.WriteLine(message);
}
}
I have every class and method set to public
I am calling config.UseServiceBus(); in my program.cs file
Im using Microsoft.Azure.WebJobs v 1.1.2
((Im not entirely sure I have written the correct AzureWebJobsDashboard- and AzureWebJobsStorage-connectionstrings, I took them from my only Azure storage-settings in Azure portal. If that might be the problem, where should I get them ))
According to your mentioned error, it seems that you miss parameter config for ininitializing JobHost. If it is that case, please use the following code.
JobHost host = new JobHost(config)
More detail info about how to use Azure Service Bus with the WebJobs SDK please refer to the document.The following is the sample code from document.
public class Program
{
public static void Main()
{
JobHostConfiguration config = new JobHostConfiguration();
config.UseServiceBus();
JobHost host = new JobHost(config);
host.RunAndBlock();
}
}