azure-sdk-for-net
azure-sdk-for-net copied to clipboard
[QUERY] SQL query eventgridevent error after migrating
Library name and version
Azure.Messaging.EventGrid 4.13.0
Query/Question
Before moving to Azure.Messaging we had a HttpTrigger which would make use of bindings to fetch EventGridEvent via Microsoft.Azure.Webjobs.CosmosDBAttribute SQL query, like so:
[HttpTrigger(AuthorizationLevel.Function, "post", Route = "feedbacks//{itemId}")] HttpRequest req, Guid itemId, [CosmosDB( databaseName:"events", containerName:"log", Connection ="CosmosConnection", SqlQuery = "SELECT * FROM c WHERE c.data.id = {itemId} ORDER BY c._ts DESC" )] IEnumerable<EventGridEvent> feedbackEvents, ILogger log)
However after moving we're now getting the following error:
System.Private.CoreLib: Exception while executing function: ScheduleHandler. Microsoft.Azure.WebJobs.Host: Exception binding parameter 'feedbackEvents'. Newtonsoft.Json: Unable to find a constructor to use for type Azure.Messaging.EventGrid.EventGridEvent. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Path '[0].Type', line 1, po
My question is have Azure.Messaging.EventGrid gotten rid of being able to fetch EventGridEvents like I wrote, or am I doing something completly wrong?
Environment
.NET 6 Azure Functions Runtime v4 Visual Studio 2022 version 17.4.3
Thank you for your feedback. Tagging and routing to the team member best able to assist.
Hi @MikkelGlerup, It looks like you are trying to use the new EventGridEvent type with an HttpTrigger. This won't work as the HttpTrigger doesn't know about the new model so it ends up using the NewtonSoft deserialization to attempt to construct the model. If you instead use the EventGrid trigger included in the Event Grid WebJobs extension, then things should work.
Samples can be found here.
Hi @MikkelGlerup. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text “/unresolve” to remove the “issue-addressed” label and continue the conversation.
/unresolve
Hello @JoshLove-msft You're writing that this is happening because we use a HttpTrigger instead of an EventGridTrigger, and sadly switching around to using EventGridTrigger would require quite a bit of restructiring of our function.
However prior to updating from the now deprecated Microsoft.Azure.Eventgrid we were able to make use of Microsoft.Azure.EventGrid.Models to deserialize the event in the HttpTrigger.
Is this just a feature that has been completely removed then?
Correct, the EventGridEvent model in Azure.Messaging.EventGrid does not integrate with NewtonSoft so it cannot be deserialized automatically in the same way that the legacy model can.
Hi, we're sending this friendly reminder because we haven't heard back from you in 7 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!