botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

[Question] Microsoft.Bot.Connector.CardAction.set_Value() Throwing Exception

Open operacha opened this issue 9 years ago • 12 comments

System Information (Required)

  • SDK Language: .NET/C#
  • SDK Version: 3.8.1.0
  • Development Environment: LOCALHOST

Issue Description

Currently using AuthBot library (https://github.com/MicrosoftDX/AuthBot) for Azure Active Directory authentication with BotBuilder. When I use the sample provided in the GitHub repo for AuthBot the program compiles and works as expected but when I use the same piece of code in the bot I am creating I get an exception from Microsoft.Bot.Connector.CardAction.set_Value().

Code Example

Below is the code snippet that is causing the issue. Issue seems to occur at var message = await result;

public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> item)
{
    var message = await item;

    if (message.Text == "logon")
    {
         //endpoint v1
         if (string.IsNullOrEmpty(await context.GetAccessToken(ConfigurationManager.AppSettings["ActiveDirectory.ResourceId"])))
         {
               await context.Forward(new AzureAuthDialog(ConfigurationManager.AppSettings["ActiveDirectory.ResourceId"]), this.ResumeAfterAuth, message, CancellationToken.None);
          }
         else
         {
               context.Wait(MessageReceivedAsync);
         }
     }
}
        
 private async Task ResumeAfterAuth(IDialogContext context, IAwaitable<string> result)
 {
     var message = await result;

     await context.PostAsync(message);
     context.Wait(MessageReceivedAsync);
}

Steps to Reproduce

  1. Run bot using localhost in bot emulator
  2. Send message 'logon'
  3. Exception is thrown

Expected Behavior

After sending 'logon' the expected behaviour is to get a response from bot with instructions to authenticate:

Expected response in chat: image

Actual Results

What actually happens is in the chat a response is sent "Exception: Stack is empty" with an exception thrown in Visual Studio

Chatbot reponse: image

Visual Studio exception from debugger: image

operacha avatar Jun 05 '17 15:06 operacha

@operacha Hello, could you please post the code where you are constructing the adaptive card?

JasonSowers avatar Jun 05 '17 16:06 JasonSowers

@JasonSowers

Would this be what you're looking for?

private List<CardAction> GetCardActions(string authenticationUrl, string actionType)
        {
            List<CardAction> cardButtons = new List<CardAction>();
            CardAction plButton = new CardAction()
            {
                Value = authenticationUrl,
                Type = actionType,
                Title = "Authentication Required"
            };
            cardButtons.Add(plButton);
            return cardButtons;
        }

operacha avatar Jun 05 '17 17:06 operacha

@operacha also what channel are you using?

JasonSowers avatar Jun 05 '17 17:06 JasonSowers

I have tried to repro the issue., but it is working fine with me. can you check the version you are using?

image

image

image

msmohan avatar Jun 05 '17 17:06 msmohan

Are you on VPN?

msmohan avatar Jun 05 '17 17:06 msmohan

@msmohan I'm running version 3.6.5-alpha for authbot

@JasonSowers I'm using localhost:44353

operacha avatar Jun 05 '17 17:06 operacha

I'm looking more for something like this method in the Authbot

        protected virtual Task PromptToLogin(IDialogContext context, IMessageActivity msg, string authenticationUrl)
        {
            Attachment plAttachment = null;
            switch (msg.ChannelId)
            {
                case "skypeforbusiness":
                    return context.PostAsync(this.prompt + "[Click here](" + authenticationUrl + ")");
                case "emulator":
                case "skype":
                    {
                        SigninCard plCard = new SigninCard(this.prompt, GetCardActions(authenticationUrl, "signin"));
                        plAttachment = plCard.ToAttachment();
                        break;
                    }
                // Teams does not yet support signin cards
                case "msteams":
                    {
                        ThumbnailCard plCard = new ThumbnailCard()
                        {
                            Title = this.prompt,
                            Subtitle = "",
                            Images = new List<CardImage>(),
                            Buttons = GetCardActions(authenticationUrl, "openUrl")
                        };
                        plAttachment = plCard.ToAttachment();
                        break;
                    }
                default:
                    {
                        SigninCard plCard = new SigninCard(this.prompt, GetCardActions(authenticationUrl, "signin"));
                        plAttachment = plCard.ToAttachment();
                        break;
                    }
//                    return context.PostAsync(this.prompt + "[Click here](" + authenticationUrl + ")");
            }

            IMessageActivity response = context.MakeMessage();
            response.Recipient = msg.From;
            response.Type = "message";

            response.Attachments = new List<Attachment>();
            response.Attachments.Add(plAttachment);

            return context.PostAsync(response);
        }

JasonSowers avatar Jun 05 '17 17:06 JasonSowers

I have two suggestions.,

  1. Check on AAD settings for any restrictions.
  2. I understand, it is not working for newer version., there is a high possibility that some of the older functions/methods changed. Let us know if you need help in identifying.

msmohan avatar Jun 05 '17 17:06 msmohan

After reviewing all., This is not BotBuilder framework related issue. It should be filed under AuthBot, https://github.com/MicrosoftDX/AuthBot/issues

image

msmohan avatar Jun 05 '17 18:06 msmohan

Closing the issue under bot-builder.

msmohan avatar Jun 05 '17 18:06 msmohan

Issue was due to AuthBot and NOT BotBuilder framework. After updating the versions and references within the code the issue was resolved.

operacha avatar Jun 06 '17 16:06 operacha

@operacha Thanks for sharing the source code with me, that enabled me to help you to identify the root cause.

msmohan avatar Jun 07 '17 01:06 msmohan