Jericho / StrongGrid

Strongly typed library for the entire SendGrid v3 API, including webhooks
182 stars 38 forks source link

nothing working on v 65.0 #408

Closed davidbutz closed 2 years ago

davidbutz commented 2 years ago

Using v 65.0 of code.

Suddenly nothing works.

Example: string templateId = "x"; var result = _client.Templates.GetAsync(templateId).ConfigureAwait(false);

blows up. New as of this weekend. SWMailLogo

Jericho commented 2 years ago

When you say "nothing works" and "blows up", what do you mean exactly? Any error message you can share? Stack trace? Any specific steps to reproduce? If appropriate, can you share the JSON returned from Sendgrid?

Jericho commented 2 years ago

Oh and by the way, version 0.65.0 is almost two years old. There's been two dozen releases since then. Have you tried upgrading to the most recent version?

Jericho commented 2 years ago

Quick observation: the code sample you included in your comment invokes an async method but does not await the result. I'm sure it's just a typo you made when raising this issue but I figured I would point it out to eliminate this possibility.

davidbutz commented 2 years ago

I know this is important. But. No. No errors. I call from a webjob to build a list of notifications . then simiilar to this function below, the message had always gone out, until this weekend....

Nothing is "caught", just returns the task back as false. will not advance past the code i mentioned above.

I know i am old. I write then expect it to work... forever? Was busy trying to get out urgent comm. so I had to port over to https://github.com/sendgrid/sendgrid-csharp

I've LOVED stronggrid in many many many projects. I know it sounded frustrated/and likely frustrating for you to not have all the pieces. I've shared what I can for now..

public async Task<Boolean> SendInternalStaffMessage(string subject, string message, string email, string name)
{
    try
    {
        string templateId = "d-ddd6f9533a8545c99c6360b74ba6c367";
        var dynamicTemplate = await _client.Templates.GetAsync(templateId).ConfigureAwait(false);

        var dynamicData = new
        {
            Subject = subject,
            Message = message
        };
        var toList = new List<StrongGrid.Models.MailAddress>()
        {
            new StrongGrid.Models.MailAddress("dbutz@selectivewm.com","David Butz"),
            new StrongGrid.Models.MailAddress(email,name),
        };

        var from = new StrongGrid.Models.MailAddress("info@selectivewm.com", "Selective Wealth Management");

        try
        {
            var messageId = await _client.Mail.SendToMultipleRecipientsAsync(toList, from, templateId, dynamicData).ConfigureAwait(false);
            return true;
        }
        catch (Exception e)
        {
            var mistake = e.Message;
            return false;
        }
    }
    catch (Exception e)
    {
        Console.WriteLine(e.Message);
        return false;
    }
}
Jericho commented 2 years ago

Looking at the code you posted, it looks like you return "false" when an exception is caught:

        catch (Exception e)
        {
            var mistake = e.Message;
            return false;
        }

and also:

    catch (Exception e)
    {
        Console.WriteLine(e.Message);
        return false;
    }

So, the fact that you say it just returns the task back as false leads me to believe that an exception is actually caught and your code swallows it. I bet you would see the actual error if you removed the "catch".

davidbutz commented 2 years ago

You can close this. I simply cannot explain it. But... I rewrote EVERYTHING to use SendGrid's package. Deployed. Then for kicks and giggles wanted to get you a better error- for everyone's sake. And Voila! It is working. The ONLY change was adding a use StrongGrid; statement atop my class.

Jericho commented 2 years ago

It would have been cool to get to the bottom of it and figure out what was causing the issue but I'm glad it's now working.

I'll close this issue but I'll be more than happy to reopen if you ever get more details.