Search code examples
.netazureazure-functionssignalrazure-eventgrid

Azure Function EventGridTrigger: Error binding parameter


I'm having troubles to get this function (back) to work. (At least I think it worked last week). Today I started experimenting with SignalR and Installed the Package "Microsoft.Azure.WebJobs.Extensions.SignalRService" Version="1.6.0" and now if I start my Azure function in Debug Mode (with visual Studio) I am getting the following error:

Microsoft.Azure.WebJobs.Host: Error indexing method 'AiAssetJobFinishedTrigger'. Microsoft.Azure.WebJobs.Host: Unable to resolve binding parameter 'eventGridEvent'. Binding expressions must map to either a value provided by the trigger or a property of the value the trigger is bound to, or must be a system binding expression (e.g. sys.randguid, sys.utcnow, etc.).

I already tried things like:

  • renaming the variable from eventGridEvent to eve or just e, no change
  • Changed the order of the bindings
  • removed the SignalR package

I have no clue why this is happening.

Code:

 [FunctionName("AiAssetJobFinishedTrigger")]
        public static void AiEventHandler(
            [EventGridTrigger] EventGridEvent eventGridEvent,
            [CosmosDB(
                databaseName: "%COSMOS_DB_DATABASE_NAME%",
                collectionName: "%COSMOS_DB_CONTAINER_ID%",
                ConnectionStringSetting = "COSMOS_DB_CONNECTION_STRING",
                Id = "{eventGridEvent}",
                PartitionKey = "{eventGridEvent}")] AiAssetStatus aiAssetStatus,
            [CosmosDB(
                databaseName : "%COSMOS_DB_DATABASE_NAME%",
                collectionName :  "%COSMOS_DB_CONTAINER_ID%",
                ConnectionStringSetting =  "COSMOS_DB_CONNECTION_STRING")]out AiAssetStatus statusOut, ILogger log)
        {
            log.LogInformation("Event received type: {type} - subject: {subject} - data {data}", eventGridEvent.EventType, eventGridEvent.Subject, eventGridEvent.Data);

            log.LogInformation(aiAssetStatus.ToString());

            aiAssetStatus.status = AiStatus.Ready;
            aiAssetStatus.lastUpdate = DateTime.UtcNow;

            //TODO: send Event to UI SignalR

            log.LogInformation("Write status for ai asset creation to database");
            statusOut = aiAssetStatus;
        }

Probably the same issue like here: Accessing EventGridEvent.EventType in Azure function binding

[Edit - 02.11.2021 - 21:32]

After removing this part of the binding it is working:

[CosmosDB(
                databaseName: "%COSMOS_DB_DATABASE_NAME%",
                collectionName: "%COSMOS_DB_CONTAINER_ID%",
                ConnectionStringSetting = "COSMOS_DB_CONNECTION_STRING",
                Id = "{eventGridEvent}",
                PartitionKey = "{eventGridEvent}")] AiAssetStatus aiAssetStatus

Is there any chance to use this binding?


Solution

  • After removing this part of the binding it is working:

    [CosmosDB(
                    databaseName: "%COSMOS_DB_DATABASE_NAME%",
                    collectionName: "%COSMOS_DB_CONTAINER_ID%",
                    ConnectionStringSetting = "COSMOS_DB_CONNECTION_STRING",
                    Id = "{eventGridEvent}",
                    PartitionKey = "{eventGridEvent}")] AiAssetStatus aiAssetStatus