Edi
Edi

Reputation: 660

Sendgrid System.ArgumentException: Unknown element: html

I've just update the following packages to their latest version:

a) SendGrid.SmtpApi updated to 1.3.1

b) SendGrid update to 6.0

and suddenly the WebTransport.Deliver method is not there anymore - no problem, I've switched to DeliverAsync method but now I get a very strange error, that it's supposed to be fixed since 2 years ago:

System.ArgumentException: Unknown element: html

This is part of the stack trace that can be of interest:

System.ArgumentException: Unknown element: html

at SendGrid.ErrorChecker.CheckForErrors(HttpResponseMessage response, Stream stream)

at SendGrid.ErrorChecker.d__0.MoveNext()

--- End of stack trace from previous location where 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 stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

And also this is how my 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, please, someone tell me what is happening?

Thank you, Evdin

Upvotes: 3

Views: 792

Answers (1)

bwest
bwest

Reputation: 9854

Please update to 6.0.1, there was a bug in 6.0.0 and it was unlisted. Thanks.

https://github.com/sendgrid/sendgrid-csharp/blob/master/CHANGELOG.md

Upvotes: 4

Related Questions