Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

Error in SendEmailAfterSubmissionActor when accessing HttpRequestContext

Vote:
0

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:
0

Can you post the full stacktrace?

#335986
Jan 23, 2025 13:10
Vote:
0
   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:
0

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:
0

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
* 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.