London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

Error in SendEmailAfterSubmissionActor when accessing HttpRequestContext

Vote:
 

Hi!

After upgrade to .net 9 and CMS 12.32.2 we get an error when we are trying to read the HttpRequestContext. Forms are version 5.10.2

This is the code:

public class SendEmailAfterSubmissionActor : EPiServer.Forms.Implementation.Actors.SendEmailAfterSubmissionActor
{
    private readonly SmtpSettings _smtpSettings;
    private readonly PlaceHolderService _placeHolderService;
    private readonly SmtpClient _smtpClient;
    private readonly XhtmlRenderService _xhtmlRenderService;

    public SendEmailAfterSubmissionActor(SmtpSettings smtpSettings, PlaceHolderService placeHolderService, XhtmlRenderService xhtmlRenderService)
    {
        _smtpSettings = smtpSettings;
        _placeHolderService = placeHolderService;
        _xhtmlRenderService = xhtmlRenderService;
        _smtpClient = new(_smtpSettings.Host, _smtpSettings.Port)
        {
            DeliveryMethod = _smtpSettings.DeliveryMethod,
            PickupDirectoryLocation = _smtpSettings.PickupDirectoryLocation
        };
    }

    public override object Run(object input)
    {
        if (!(Model is IEnumerable<EmailTemplateActorModel> emailTemplateActorModels) || !emailTemplateActorModels.Any())
        {
            _logger.Debug("There is no collection of EmailTemplateActorModel for this actor to work.");
            return null;
        }

        foreach (var actorModel in emailTemplateActorModels)
        {
            SendMessage(actorModel);
        }

        return null;
    }

public void SendMessage(EmailTemplateActorModel emailTemplateActorModel)
{
...
   if (HttpRequestContext?.Form?.Files != null && HttpRequestContext.Form.Files.Count > 0)
...
}

And it gives me this error

Unexpected end of Stream, the content may have already been read by another component

I can watch the object in debug mode and Form is null, since it is a post I guess there should be a form available?

Does any know why this is happening?

Thanks!

/Kristoffer

#335985
Jan 23, 2025 12:13
Vote:
 

Can you post the full stacktrace?

#335986
Jan 23, 2025 13:10
Vote:
 
   at Microsoft.AspNetCore.WebUtilities.MultipartReaderStream.<ReadAsync>d__38.MoveNext()
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at System.Runtime.CompilerServices.ValueTaskAwaiter`1.GetResult()
   at Microsoft.AspNetCore.WebUtilities.StreamHelperExtensions.<DrainAsync>d__3.MoveNext()
   at Microsoft.AspNetCore.WebUtilities.MultipartReader.<ReadNextSectionAsync>d__20.MoveNext()
   at Microsoft.AspNetCore.Http.Features.FormFeature.<InnerReadFormAsync>d__24.MoveNext()
   at Microsoft.AspNetCore.Http.Features.FormFeature.ReadForm()
   at Klaranatet.Web.Core.Infrastructure.EpiServerForms.SubmissionActors.SendEmailAfterSubmissionActor.SendMessage(EmailTemplateActorModel emailTemplateActorModel) in C:\Users\Utv2\Projects\Klaranatet.Web\Klaranatet.Web.Core\Infrastructure\EpiServerForms\SubmissionActors\SendEmailAfterSubmissionActor.cs:line 120
#335987
Edited, Jan 23, 2025 13:43
Vote:
 

Hi Quan!

Did you find anyhing? Should I report a bug?

Thanks!

/Kristoffer

#336035
Jan 24, 2025 9:35
Quan Mai - Jan 24, 2025 9:51
No I haven't. Had no time to look into this, yet. Please contact our developer support service for further assistance
Vote:
 

Hi Krisoffer,

It's a known bug of Opti form.
A temporary workaround is your actor need to implement ISyncOrderedSubmissionActor  and set the IsSyncedWithSubmissionProcess to true.

public class SendEmailAfterSubmissionActor: EPiServer.Forms.Implementation.Actors.SendEmailAfterSubmissionActor
{
    ..........
    public override bool IsSyncedWithSubmissionProcess => true;
}

 
I know that, when implementing the ISyncOrderedSubmissionActor , the actors will run as synchronously instead of Async. But it is the only temporary solution while waiting for the issue to be fixed.

#336040
Edited, Jan 24, 2025 11:31
Vote:
 

We have the same problem. Does anyone know when this will be solved from Optimizely? 

#337696
Apr 03, 2025 7:20
Vote:
 

A know bug since more than two months, it should be solved but maybe it isn't? Have you upgraded to latest version?

#337697
Apr 03, 2025 7:22
Vote:
 

Yes latest is 5.10.4 on Forms so no update so far... 

Another fun fact is that someone made me end up on the integration environment for World https://inte.world.optimizely.com/forum/developer-forum/cms-12/thread-container/2025/1/error-in-sendemailaftersubmissionactor-when-accessing-httprequestcontext/  Did not know this was possible :) So replyed twice on this post.. 

#337699
Apr 03, 2025 8:15
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.