Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Alexander 31 posts 81 karma points
    Sep 13, 2019 @ 05:23

    Umbraco 8 Component ContentService.Published Async Action Kills IIS


    I'm running Umbraco 8. I have a quite simple scenario:

    1. Umbraco component is subscribed to ContentService.Published action and have some conditions.
    2. If conditions are true I need to send an email to the user. For emails, I'm using SendGrid, which is very common in our days. Sendgrid nuget package provides only async method to send an email. And it doesn't work when I call it from the ContentPublished event handler.
    3. Moreover, whatever async method I call from the event handler kills IIS with Async Lock error.

    In component initialize I have:

    ContentService.Published += OnPublishedPage;

    Handler code looks like this:

    // async doesn't work here and kills IIS
    var response = _emailSender.SendUserDownloadEmailAsync(members, tender).GetAwaiter().GetResult();

    Is there any workaround or could you please point me to the right direction?

    Thanks, Alexander.

  • Stephen 767 posts 2272 karma points c-trib
    Sep 13, 2019 @ 16:46

    Interesting. Can you ... try to replace whatever happens in SendUserDownloadEmailAsync by a simple await Task.Delay(100) and see whether it still causes the error?

    In which case, the error is narrowed down to the async call. Otherwise, it might have to do with Sendgrid.

    Now... do you have details about "the event handler kills IIS with Async Lock error" - is it the entire w3wp process that dies? Where do you see the error? In the Event Log or in Umbraco's log? Can we have the full details on the error?

    Suspecting some threading issue with the async call...

  • Thomas 159 posts 334 karma points
    Dec 16, 2020 @ 08:43

    Well i have probably the same issue when i was trying to call an async method to post in facebook and twitter walls. Within the Published event when i was calling the async method in order to fire and forget, i didn't want the user to wait when the facebook and twitter posts will be completed, it looks that i had the same problem. And how i realize it? I was trying to get the Url of the published content. Without the async call everything was fine. With the async call, i was getting the IPublishedContent from the umbraco context but when i was trying to retrieve values i was getting null reference exception. Somehow the umbraco context dropped, and it couldn't retrieve the values.

    Any suggestions how to resolve it? Fire and Forget like send an email or post to facebook wall are required, it must not make the user to wait until finish.

    Following are the pictures when i retrieve the IPublishedContent with the values in the properties (Quick Watch print screen) and then when i try to retrieve the values from code the null reference exception.

    Quick Watch with the values

    Null reference from code

Please Sign in or register to post replies

Write your reply to: