3

On SubmitAction action in Adaptive Cards (botframework, c#, emulator, localhost) I get this Exception

Exception: Value cannot be null. Parameter name: stringToEscape
[File of type 'text/plain']

Can you help me point out what am doing wrong?

card.Actions.Add(
    new SubmitAction()
    {
        Title = "Submit"
        Data = Newtonsoft.Json.Linq.JObject.FromObject(new { button = "Submit", ServerUrl = "idServerURL" })
    }
);

From RootDialog - LUIS Intent is called

[LuisIntent("ServerAuth")]
public async Task ServerAuthIntentActionResultHandlerAsync(IDialogContext 
context, IAwaitable<IMessageActivity> activity, LuisResult result)
{
    var message = await activity;
    await context.PostAsync($"Am working on it...'{message.Text}' ");

    var serverAuthAction = new ServerAuthAction();

    // Action to execute if no form is required - Based on LUIS result, call fulfillment methods From/To ERP Data and proceed to next stage of dialog
    await serverAuthAction.ResumeActionServerAuthFormDialog(context, result);

    //context.Wait(this.MessageReceived);

}

public async Task ResumeActionServerAuthFormDialog(IDialogContext context, LuisResult result)
{
    try
    {
        //Based on the LUIS Result, fetch data from AppServer
        //var searchQuery =  result;

        //Data - Assign value to this Model from AppServer fetched data
        ServerAuthModel serverAuthData = new ServerAuthModel();
        serverAuthData = default(ServerAuthModel);

        //For testing populate values by hardcoding - /May/2017
        ServerAuthAdaptiveCardView serverAuthView = new ServerAuthAdaptiveCardView();

        //Pass Data to Channel Adaptive Card View 
        var resultData = serverAuthView.GetServerAuthAdaptiveCard();

        var resultMessage = context.MakeMessage();

        resultMessage.Attachments.Add(resultData);

        await context.PostAsync(resultMessage);
    }
    catch (Exception ex)
    {
        ...
    }
    finally
    {
        ....
    }
}

GetServerAuthAdaptiveCard() has the Submit Action code.

public Attachment GetServerAuthAdaptiveCard()
{
    AdaptiveCard card = new AdaptiveCard();
    card.FallbackText = "App Server Authentication";
    card.Body.Add(
        new TextInput()
        {
            Id = "idServerURL",
            IsRequired = true,
            Placeholder = "App Server URL",
            MaxLength = 100,
            IsMultiline = false,
            Style = TextInputStyle.Url,
            Speak = "App Server URL",
        });

    card.Body.Add(
        new ChoiceSet()
        {
            Id = "idAuthCompany",
            IsRequired = true,
            IsMultiSelect = false,
            Style = ChoiceInputStyle.Compact,
            Speak = "Company to Authenticate for",
            Value = "DocM5",
            Choices = new List<Choice>() {
                new Choice()
                {
                    Title = "P2PDemo",
                    Value = "P2PDemo",
                    IsSelected = true,
                    Speak = "P2PDemo"
                },
                new Choice()
                {
                    Title = "SalesDemo",
                    Value = "SalesDemo",
                    IsSelected = false,
                    Speak = "SalesDemo"
                }
            }
        });
    card.Body.Add(
        new TextInput()
        {
            Id = "idBranchName",
            IsRequired = true,
            Placeholder = "App Branch",
            MaxLength = 100,
            IsMultiline = false,
            Style = TextInputStyle.Text,
            // Value = ""
        });

    var submitActionData = JObject.Parse("{ \"Type\": \"idServerURL\" }");


    card.Actions.Add(
        /*  new SubmitAction()
        {
            Title = "Submit",
            // Speak = "Submit",
            Data = Newtonsoft.Json.Linq.JObject.FromObject(new { button = "Submit", ServerUrl = "idServerURL" })
        }
        */
        new SubmitAction()
        {
            DataJson = submitActionData.ToString()
        });

    var attachment = new Attachment() { ContentType = AdaptiveCard.ContentType, Content = card };
    return attachment;
}

Exception from Emulator:

"contentType": "text/plain",
"content": "   at System.Uri.EscapeDataString(String stringToEscape)
    at Microsoft.Bot.Builder.Luis.LuisRequest.BuildUri(ILuisModel model)
    at Microsoft.Bot.Builder.Luis.LuisService.Microsoft.Bot.Builder.Luis.ILuisService.BuildUri(LuisRequest luisRequest)
    at Microsoft.Bot.Builder.Luis.Extensions.<QueryAsync>d__4.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Microsoft.Bot.Builder.Dialogs.LuisDialog`1.<MessageReceived>d__8.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.ThunkResume`1.<Rest>d__5.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Microsoft.Bot.Builder.Internals.Fibers.Wait`2.<Microsoft-Bot-Builder-Internals-Fibers-IWait<C>-PollAsync>d__19.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Microsoft.Bot.Builder.Internals.Fibers.Frame`1.<Microsoft-Bot-Builder-Internals-Fibers-IFrameLoop<C>-PollAsync>d__9.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Microsoft.Bot.Builder.Internals.Fibers.Fiber`1.<Microsoft-Bot-Builder-Internals-Fibers-IFiberLoop<C>-PollAsync>d__16.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    at Microsoft.Bot.Builder.Internals.Fibers.Wait`2.Microsoft.Bot.Builder.Internals.Fibers.IAwaiter<T>.GetResult()
    at Microsoft.Bot.Builder.Dialogs.Chain.LoopDialog`1.<ResumeAsync>d__3.MoveNext()
    -- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.ThunkResume`1.<Rest>d__5.MoveNext()
    --- End of stack trace from previous location where exception was thrown --
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Microsoft.Bot.Builder.Internals.Fibers.Wait`2.<Microsoft-Bot-Builder-Internals-Fibers-IWait<C>-PollAsync>d__19.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Microsoft.Bot.Builder.Internals.Fibers.Frame`1.<Microsoft-Bot-Builder-Internals-Fibers-IFrameLoop<C>-PollAsync>d__9.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Microsoft.Bot.Builder.Internals.Fibers.Fiber`1.<Microsoft-Bot-Builder-Internals-Fibers-IFiberLoop<C>-PollAsync>d__16.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.<Microsoft-Bot-Builder-Base-IEventLoop-PollAsync>d__23.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Microsoft.Bot.Builder.Dialogs.Internals.ReactiveDialogTask.<Microsoft-Bot-Builder-Base-IEventLoop-PollAsync>d__3.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Microsoft.Bot.Builder.Dialogs.Internals.ScoringEventLoop`1.<Microsoft-Bot-Builder-Base-IEventLoop-PollAsync>d__5.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Microsoft.Bot.Builder.Dialogs.Internals.EventLoopDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__3.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Microsoft.Bot.Builder.Dialogs.Internals.SetAmbientThreadCulture.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__3.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Microsoft.Bot.Builder.Dialogs.Internals.QueueDrainingDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__4.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Microsoft.Bot.Builder.Dialogs.Internals.PersistentDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__3.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
    at Microsoft.Bot.Builder.Dialogs.Internals.PersistentDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__3.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Microsoft.Bot.Builder.Dialogs.Internals.ExceptionTranslationDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__2.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Microsoft.Bot.Builder.Dialogs.Internals.SerializeByConversation.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__4.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Microsoft.Bot.Builder.Dialogs.Internals.PostUnhandledExceptionToUser.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__5.MoveNext()"
Nicolas R
  • 13,812
  • 2
  • 28
  • 57
Sangeetha
  • 53
  • 1
  • 6

3 Answers3

2

Try filling the DataJson property instead of the Data one.

var submitActionData = JObject.Parse("{ \"Type\": \"HotelSelection\" }");

var action = new SubmitAction()
{
    DataJson = submitActionData.ToString()
}

Update based on new details added to the question.

Per the full exception, the problem is around LUIS and not with the Adaptive card. Specifically, the problem is arising in the BuildUri method of the LuisService class (which is being called by the LuisDialog). The exception is also telling us that the problem is happening when the EscapeDataString method is being called.

If you look carefully to the BuildUri method, you will see that there are 10 calls to the EscapeDataString method. Some of these calls are against values from the service itself, which I don't think you are modifying; however other ones are over values from the LuisModel, like SubscriptionKey and ModelId and also there is one over the Query to be sent to LUIS.

That being said, my recommendation is to review the values you set in the LuisModel attribute that is decorating your LuisDialog based class.

If you are unsure how LUIS + Bot Framework works, I would recommend you to take a look at the intelligence-LUIS sample.

Ezequiel Jadib
  • 14,767
  • 2
  • 38
  • 43
  • hi, still have the same error "text/plain", "content": " at System.Uri.EscapeDataString(String stringToEscape)\r\n at Microsoft.Bot.Builder.Luis.LuisRequest.BuildUri(ILuisModel model)\r\n at Microsoft.Bot.Builder.Luis.LuisService.Microsoft.Bot.Builder.Luis.ILuisService.BuildUri(LuisRequest luisRequest)\r\n at Microsoft.Bot.Builder.Luis.Extensions.d__4.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n – Sangeetha Jun 01 '17 at 04:55
  • As @EzequielJadib mentioned, the log is about Luis. Can you explain what you are typing in your emulator, and add more info about your Luis intents? I just tested the adaptiveCard without LUIS and it's working (even with your initial SubmitAction) – Nicolas R Jun 02 '17 at 11:23
  • 1
    @BotHandler I just updated my answer with all the details about the error you are getting and my recommendation on where to look at. LMK – Ezequiel Jadib Jun 02 '17 at 12:10
  • thanks to both of you for the feedback. The same LUIS Model based other intents are working. I have used Receipt Card and Signin Card which is working but not Adaptive Card. As suggested, I will try now without LUIS Model and give feedback. – Sangeetha Jun 02 '17 at 13:13
  • @BotHandler the issue happens when you click on the button? If so, do the following, override the MessageReceived of your LuisDialog based class and inspect the text coming, I suspect we are closer... – Ezequiel Jadib Jun 02 '17 at 13:21
  • Implemented as GlobalMessageHandlers/Scorables (I assumed LuisDialog wont be there in this kind of implementation). Even then I get same error – Sangeetha Jun 02 '17 at 14:08
  • 1
    @BotHandler stop the ball :) you are not reading our comments. Publish your code in Github so we can take a look – Ezequiel Jadib Jun 02 '17 at 14:09
  • https://drive.google.com/open?id=0B6c7_QUBM0vTaXU4VjJMZVFsVHc has the similar exception text i get now – Sangeetha Jun 02 '17 at 14:15
  • We all know the exception, that was clear :) I already explained the source of the exception; in order to understand why in your code is happening we need to take a look to it and/or we need more details eg: is the issue happening when you click on the button? – Ezequiel Jadib Jun 02 '17 at 14:18
  • Sorry, i might have missed few comments in between. I will publish code and let know. Got to segregate this piece of code;will do soon. Thanks for the help – Sangeetha Jun 02 '17 at 14:19
  • 1) Yes it happens when I click Submit 2) Am not sure why LuisService is called when this is implemented using Scorables and same exception occurs. 3) I will stop confusing further and publish code and let know. Thanks again :) – Sangeetha Jun 02 '17 at 14:23
  • @EzequielJadib have published the code here https://github.com/bothandler/AdaptiveCardTest. Kindly take a look. The LUIS Model is in the same folder Authenticate.json – Sangeetha Jun 05 '17 at 17:42
0

You are getting this error because when you click on the submit button on Adaptive card it calls the POST method of your BOT Framework. At which time Activity.Text field is NULL. You should check in the POST method if Activity.Text field is NULL; if it is, then you should not call LUIS for the intent check.

ale
  • 6,369
  • 7
  • 55
  • 65
0

This is how I did it, to make it work for Microsoft teams. Else for the emulator, you simply pass a string in Data.

dynamic dataObject = new JObject();
dataObject.msteams = new JObject();
dataObject.msteams.type = "imBack";
dataObject.msteams.value = intent.Value;
var actionSubmit = new AdaptiveSubmitAction(){
    Title = intent.Value,
    Data = turnContext.Activity.ChannelId != "emulator" ?  dataObject : intent.Value
};
Piotr Labunski
  • 1,638
  • 4
  • 19
  • 26
Justin
  • 91
  • 8