-
Notifications
You must be signed in to change notification settings - Fork 181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A 'To' address must be specified for the message using SendGridOutput #737
Comments
Thanks @AsierVillanueva for reporting the issue. From the initial investigation, it looks like this is caused by the conflicting JSON serializers being used (SendGrid Relevant part of the (incorrect) JSON produced (and sent form worker to host)
Ideally, it should be Just to confirm from your side as well, do you still see the issue when you use newtonsoft JSON.NET serializer? Refer this sample bootstrapping code to configure JSON.NET as serializer. (You need to add a reference to the
|
Confirmed, with JSON.NET as serializer works fine. |
As a workaround, it would be possible to set a serializer only for a specific function? |
No, it is not possible to set a serializer only for a specific function. The serializer you set on the bootstrapping code (inside |
@AsierVillanueva We will discuss this item in the next triage meeting and will share an update. Until we have a proper official fix/guidance available, one 🐎 hacky solution to mitigate the issue is to create your own local copy of the SendGridMessage type and use JsonPropertyName attribute from STJ to customize the property names in the JSON string and use that. Here is a minimal version of the type definition I used for validating.
and your function code will use it like this.
|
Ok. My types for workaround:
So the function code is almost the same:
|
@AsierVillanueva Another solution is to explicitly generate the JSON string of your Here is a working sample. With this approach you do not need to duplicate the types locally. You can use the types coming from the
Hope that helps. Let us know if you run into any issues. |
Same problem with |
Based on the investigation done by @kshyju, a custom converter for this extension would be appropriate. Leaving this issue open to track that work and follow up on the SendGrid repo to see if they can also make enhancements to support System.Text.Json |
Link to the issue they're using to track the move to STJ: sendgrid/sendgrid-csharp#985 |
@AsierVillanueva Another solution is to write some custom System.Text.Json JsonConverter implementations and hook it up with the function application during bootstrapping. S.T.J serializer will use these converters to customize the serialization result and you should be able to generate a JSON String which is similar to the JSON string produced by JSON.NET. Here is a minimal working sample which uses some custom STJ converters to solve this issue. Hope this helps. There is an open issue in the sendgrid repo to support STJ use case. Once they publish a new version of the library, we will publish a new version of the sendgrid extension to reflect that. Closing this issue as there are various solutions to solve the problem at this point. |
When I try to send a email with SendGrid binding the Azure Function output with SendGridOutputAttribute then function fail with this error: A 'To' address must be specified for the message.
I use .NET 5.0 dotnet-isolated runtime.
Sample code:
When I call the function the response is:
The text was updated successfully, but these errors were encountered: