2
votes

I'm new in Bot framework and I face this issue:

I want to move from dialog to another dialog, the callback function is working for context.Call but not for context.Forward? I try multiple solutions such as put this.CallbackFunctionName but it dosen't work.

Here is my code for call new dialog:

switch (submitType)
{
    case "alarm":
        context.Call(new AlarmDialog(), ResumeAfterAlarmDialog);
        context.Done(true);
        return;

    case "game":
        await context.Forward(new AlarmDialog(), ResumeAfterAlarmDialog, value, CancellationToken.None);
        return;
    }

And here the method that I call:

private async Task ResumeAfterAlarmDialog(IDialogContext context, IAwaitable<object> result)
{
    await context.PostAsync($"You are finish the alarm dialog");
    context.Wait(this.MessageReceivedAsync);
}

And this is the error that I have for the context.Forward:

cannot use a method group as an argument to a dynamically dispatched operation.Did you intend to invoke the method?

Here the full implementation of the class:

    namespace CardEx.Dialogs
{
    [Serializable]
    public class RootDialog : IDialog<object>
    {
        public Task StartAsync(IDialogContext context)
        {
            context.Wait(MessageReceivedAsync);

            return Task.CompletedTask;
        }

        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
        {
            var activity = await result as Activity;

            if (activity.Value != null)
            {
                // Got an Action Submit
                dynamic value = activity.Value;
                string submitType = value.Type.ToString();
                switch (submitType)
                {
                    case "alarm":

                        context.Call(new AlarmDialog(), ResumeAfterAlarmDialog);

                        return;

                    case "alarm2":
                        await context.Forward(new AlarmDialog(), ResumeAfterAlarmDialog, value, CancellationToken.None);
                        return;
                }
            }


            AdaptiveCard aCard = new AdaptiveCard()
            {
                Body = new List<AdaptiveElement>()
    {
            new AdaptiveTextBlock()
            {
                Text = "Welcome!",
                Weight = AdaptiveTextWeight.Bolder,
                Size = AdaptiveTextSize.Large
            },
            new AdaptiveTextBlock() { Text = "Please choose one of the following:" },

    },
                Actions = new List<AdaptiveAction>()
    {
        new AdaptiveSubmitAction()
        {
            Title = "Set an alarm",
            DataJson = "{ \"Type\": \"alarm\" }"
        },
        new AdaptiveSubmitAction()
        {
            Title = "Play a game",
            DataJson = "{ \"Type\": \"game\" }"
        }
    }
            };

            Attachment attachment = new Attachment()
            {
                ContentType = AdaptiveCard.ContentType,
                Content = aCard

            };

            var reply = context.MakeMessage();
            reply.Attachments.Add(attachment);

            await context.PostAsync(reply, CancellationToken.None);

            context.Wait(MessageReceivedAsync);
        }
        private async Task ResumeAfterAlarmDialog(IDialogContext context, IAwaitable<object> result)
        {
            await context.PostAsync($"You are finish the alarm dialog");
            context.Wait(this.MessageReceivedAsync);
        }

    }
}

Thank you.

1
Can you add the full code of your class please?Nicolas R
Based on the code snippet that you provided, it is difficult to find the root cause of issue. Please share your full code or a sample to reproduce the issue.Fei Han
@FeiHan I add the code, thank you.Ahmad Dar Saleh
@NicolasR I add the code, thank you.Ahmad Dar Saleh

1 Answers

1
votes

cannot use a method group as an argument to a dynamically dispatched operation.Did you intend to invoke the method?

the parameter value used in context.Forward is a dynamic type, which raised this issue.

Please try following code:

await context.Forward(new TestDialog(), ResumeAfterAlarmDialog, (object)value, CancellationToken.None);