Sendgrid System.ArgumentException: Unknown element: html
I just updated the following packages to their latest version:
a) SendGrid.SmtpApi updated to 1.3.1
b) Update SendGrid to version 6.0
and suddenly the WebTransport.Deliver method no longer exists - no problem, I switched to the DeliverAsync method, but now I am getting a very strange error that it has to fix from 2 years ago:
System.ArgumentException: Unknown element: html
This is the part of the stack trace that might be of interest:
System.ArgumentException: Unknown element: html
at SendGrid.ErrorChecker.CheckForErrors (HttpResponseMessage Response, Stream Stream)
at SendGrid.ErrorChecker.d__0.MoveNext ()
--- End of the stack trace from the previous location where the exception was thrown -
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (Task Task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (Task Task)
at SendGrid.Web.d__0.MoveNext ()
--- End of the stack trace from the previous location where the exception was thrown - to System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (Task Task)
And this is how the email sending code looks like:
SendGridMessage emailMessage = new SendGridMessage();
emailMessage.AddTo(user.CompleteRegistrationModel.UserEmailAddress);
emailMessage.From = new MailAddress(ConfigurationHelper.EmailSenderAddress, ConfigurationHelper.EmailSenderName);
emailMessage.EnableTemplateEngine(ConfigurationHelper.ConfirmationEmailTemplateId);
emailMessage.AddSubstitution("-urlaplicatie-",
new List<string>()
{
String.Format("{2}{0}{1}", user.CompleteRegistrationModel.CompanyUrlPrefix,
ConfigurationHelper.DomainSuffix, ConfigurationHelper.ApplicationAccessProtocol)
});
emailMessage.AddSubstitution("-username-",
new List<string>() {user.CompleteRegistrationModel.UserEmailAddress});
emailMessage.AddSubstitution("-confirmationurl-",
new List<string>() {user.CompleteRegistrationModel.UserEmailAddressConfirmationCompleteUrl});
emailMessage.Subject = String.Format("{0}{1}", user.CompleteRegistrationModel.CompanyUrlPrefix,
ConfigurationHelper.DomainSuffix);
emailMessage.Text = " ";
emailMessage.Html = " ";
Web webTransport =
new Web(new NetworkCredential(ConfigurationHelper.SendgridUsername,
ConfigurationHelper.SendgridPassword));
try
{
await webTransport.DeliverAsync(emailMessage);
}
catch (InvalidApiRequestException exception)
{
Elmah.ErrorSignal.FromCurrentContext().Raise(exception);
}
Can someone please tell me what is going on?
Thanks, Evdin
source to share
Upgrade to 6.0.1, there was a bug in 6.0.0 and it was not listed. Thank.
https://github.com/sendgrid/sendgrid-csharp/blob/master/CHANGELOG.md
source to share