[LUIS] Messages are hitting LUIS app but getting error in emulator
Pre-flight checklist
- [ ] I posted a question about this issue on Stack Overflow using the tag
botframework. - [x] I have searched the existing issues before logging a new one.
System Information (Required)
- SDK: .NET
- Development Environment: localhost
Issue Description
My messages are hitting the LUIS app endpoint but I see the emulator message as "couldn't send retry" POST 500 and Exception: None [File of type 'text/plain']
Example Code
public class SimpleLUIS : LuisDialog
[LuisIntent("credit")]
public async Task check(IDialogContext context, LuisResult result)
{
await context.PostAsync($"credit");
context.Wait(MessageReceived);
}
[LuisIntent("None")]
public async Task Nonecheck(IDialogContext context, LuisRequest result)
{
await context.PostAsync($"I'm not able to detect this");
context.Wait(MessageReceived);
}
}
Expected Behavior
receive the appropriate message
Actual Results

"type": "message",
"timestamp": "2017-05-26T10:44:04.501Z",
"localTimestamp": "2017-05-26T03:44:04-07:00",
"serviceUrl": "http://127.0.0.1:61170",
"channelId": "emulator",
"from": {
"id": "2h608h1nag87j3g5jc",
"name": "Bot"
},
"conversation": {
"id": "57chgbfibch9970n1c"
},
"recipient": {
"id": "default-user"
},
"membersAdded": [],
"membersRemoved": [],
"locale": "en-US",
"text": "Exception: ",
"attachments": [
{
"contentType": "text/plain",
"content": " at Microsoft.Bot.Builder.Dialogs.LuisDialog.1 source, Func2 keySelector, Func2 elementSelector, IEqualityComparer1 comparer)\r\n at Microsoft.Bot.Builder.Dialogs.LuisDialog1.GetHandlersByIntent()\r\n at Microsoft.Bot.Builder.Dialogs.LuisDialog1.1.<MessageReceived>d__8.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.ThunkResume1.2.<Microsoft-Bot-Builder-Internals-Fibers-IWait<C>-PollAsync>d__19.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Internals.Fibers.Frame1.<Microsoft-Bot-Builder-Internals-Fibers-IFrameLoop1.<Microsoft-Bot-Builder-Internals-Fibers-IFiberLoop<C>-PollAsync>d__16.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at Microsoft.Bot.Builder.Internals.Fibers.Wait2.Microsoft.Bot.Builder.Internals.Fibers.IAwaiter1.<ResumeAsync>d__3.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.ThunkResume1.2.<Microsoft-Bot-Builder-Internals-Fibers-IWait<C>-PollAsync>d__19.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Internals.Fibers.Frame1.<Microsoft-Bot-Builder-Internals-Fibers-IFrameLoop1.<Microsoft-Bot-Builder-Internals-Fibers-IFiberLoop<C>-PollAsync>d__16.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.<Microsoft-Bot-Builder-Base-IEventLoop-PollAsync>d__23.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.ReactiveDialogTask.<Microsoft-Bot-Builder-Base-IEventLoop-PollAsync>d__3.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.ScoringEventLoop1.
What version of the BotBuilder NuGet package are u using? BTW, check this, it could be related: https://stackoverflow.com/questions/41392366/how-to-use-luis-none-intent-in-c-sharp-without-train-utterance-at-luis
Hi Ezequiel, the version of BotBuilder Nuget is 3.8.1 Also used "" instead of "None" but still getting the same message "Exception: [File of type 'text/plain']". While the emulator message says "unable to send retry", i'm seeing the messages in suggested utterances.
@shakthisaran It may be because you're using:
context.Wait(MessageReceived);
was this ever solved? i am facing the same problem
Even I am facing the same issue. @shakthisaran @punjabimundaaa @JasonSowers
@shakthisaran @punjabimundaaa @BirenPanigrahi
What happens when you remove context.Wait(MessageRecieved)? Also, the above class inheritance definition should be:
public class SimpleLUIS : LuisDialog<object> {
// ...
}
not
public class SimpleLUIS : LuisDialog {
// ...
}
I hope this helps. I'm taking this from my Bot code that is also interacting with a LUIS application.
EDIT: Also, you need to include your LUIS application's information about the class declaration like so: See This StackOverflow Post
[LuisModel("Your LUIS ID" , "Your LUIS Key")]
[Serializable]
public class SimpleLUIS : LuisDialog<object> {
// ...
}
@megancooper
Thanks for your comment.
I tried removing context.Wait(MessageRecieved) but no luck.
[Serializable]
[LuisModel("xxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxx")]
public class SimpleLUISDialog : LuisDialog<object>
{
[LuisIntent("")]
[LuisIntent("None")]
public async Task None(IDialogContext context, LuisResult result)
{
await context.PostAsync("I'm sorry. I didn't understand you.");
//context.Wait(MessageReceived);
}
}
Maybe change serializable to under the LuisModel?
@megancooper nopes doesnot work. What version of Bot Framework / VS are you using?
@punjabimundaaa Sorry that didn't work. I am using version 3.8.0 of the Bot Builder and VS 2015. Could you post your full Dialog class, and your MessagesController.cs? I'm trying to see if I can recreate your exception.
@megancooper i can send you complete source code in email if that would be ok?
@punjabimundaaa I'll leave the code for a starter bot I made down below. Also, is your exception the same as the one above? If so, it looks like the bot is having problems recieving information from the LUIS application. Is the key for the LUIS application you're using hosted on Azure? If so, look at how I formatted the line LuisModel... in the RootDialog class down below.
Here is some starter code that works with a LUIS application that has one intent "help":
MessagesController.cs
namespace StarterLUISBot
{
[BotAuthentication]
public class MessagesController : ApiController
{
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
if (activity.Type == ActivityTypes.ConversationUpdate)
{
}
else if (activity.Type == ActivityTypes.Message)
{
// Sends user's Id and Name to RootDialog Class
StateClient stateClient = activity.GetStateClient();
BotData userData = await stateClient.BotState.GetUserDataAsync(activity.ChannelId, activity.From.Id);
userData.SetProperty<string>("UserId", activity.From.Id);
userData.SetProperty<string>("Name", activity.From.Name);
//other properties you want to set.
await stateClient.BotState.SetUserDataAsync(activity.ChannelId, activity.From.Id, userData);
await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
}
else if (activity.Type == ActivityTypes.Invoke)
{
}
else
{
HandleSystemMessage(activity);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}
private Activity HandleSystemMessage(Activity activity)
{
if (activity.Type == ActivityTypes.DeleteUserData)
{
// Implement user deletion here
// If we handle user deletion, return a real message
}
else if (activity.Type == ActivityTypes.ContactRelationUpdate)
{
// Handle add/remove from contact lists
// Activity.From + Activity.Action represent what happened
}
else if (activity.Type == ActivityTypes.Typing)
{
// Handle knowing tha the user is typing
}
else if (activity.Type == ActivityTypes.Ping)
{
}
return null;
}
}
RootDialog.cs
namespace StarterLUISBot.Dialogs
{
[LuisModel("ID", "AzureKey", domain: "westcentralus.api.cognitive.microsoft.com", staging: true)]
[Serializable]
public class RootDialog : LuisDialog<object>
{
// Methods that manage user's experience and settings
[LuisIntent("")]
[LuisIntent("None")]
public async Task defaultMessage(IDialogContext context, LuisResult result)
{
await context.PostAsync($"Not sure what you need to know. \n\n Type **help** for more information.");
}
[LuisIntent("Help")]
public async Task displayHelpMSG(IDialogContext context, LuisResult result)
{
await context.PostAsync($"Here's some help.");
}
}
}
Thanks Megan. I modified the controller as well as the dialog class as under. The only difference between yours and mine seem to be the domain url. I am hitting the westus
Upon initiating the conversation via emulator, I can confirm that my BOT application does make a call to LUIS and LUIS responds with correct result ( checked it via fiddler ). I guess something goes wrong in SDK when it tries to find the method for the intent returned from Luis
** Controller function **
public async Task<HttpResponseMessage> Post([FromBody]Activity activity) {
if (activity.Type == ActivityTypes.Message)
{
try
{
//await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
// Sends user's Id and Name to RootDialog Class
StateClient stateClient = activity.GetStateClient();
BotData userData = await stateClient.BotState.GetUserDataAsync(activity.ChannelId, activity.From.Id);
userData.SetProperty<string>("UserId", activity.From.Id);
userData.SetProperty<string>("Name", activity.From.Name);
//other properties you want to set.
await stateClient.BotState.SetUserDataAsync(activity.ChannelId, activity.From.Id, userData);
await Conversation.SendAsync(activity, () => new MatLuisDialog());
//await Conversation.SendAsync(activity, () => new MatLuisDialog());
}
catch (Exception ex)
{
string ss = ex.ToString();
}
}
else
{
HandleSystemMessage(activity);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}
** Luis Dialog **
[LuisModel("XXX", "XXX", domain: "westus.api.cognitive.microsoft.com",staging:true)]
[Serializable]
public class MatLuisDialog: LuisDialog<string>
{
//[LuisIntent("HelpWhoIsWhoDetailsFromName")]
//public async Task HelpWhoIsWhoDetailsFromName(IDialogContext context, LuisRequest result)
//{
// await context.PostAsync("From");
// context.Wait(MessageReceived);
//}
[LuisIntent("")]
[LuisIntent("None")]
public async Task None(IDialogContext context, LuisRequest result)
{
await context.PostAsync("No intent Found");
context.Wait(MessageReceived);
}
//[LuisIntent("Help.Greetings")]
//public async Task Greetings(IDialogContext context, LuisRequest result)
//{
// await context.PostAsync("Hi, Please enter your matone id, so that i can help you better.");
// context.Wait(MessageReceived);
//}
}
** Fiddler **

Hmm, this is strange...I'm not too sure. Could you post a picture of the error you see in the emulator/ where you're testing your bot.
When you publish your LUIS application are you choosing the "staging" Endpoint Slot? Also, the methods in your MatLuisDialog() class weren't commented out when you did the above query right?
Hey Megan Appreciate your help.
the complete project is here: https://1drv.ms/u/s!ApGwoaF4nIJolJ8OUVXNA3MYOGwQ6w
The error in the the emulator

I also made sure that application was published to staging. Upon making a get request i do get the json back
url for luis
https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/7b366454-c43c-41e8-84e2-0ab19c3225cb?subscription-key=df2e687af27a400989582c599915aea4&staging=true&timezoneOffset=0&verbose=true&q=%27who%20is%20akshay%27
@punjabimundaaa @shakthisaran
Change LuisRequest in your methods to LuisResult This fixes the issue :)
@megancooper , that fixed it. You rock Girl !!! Lemme know and i need to send you beers
PS: Have one more query on Luis will tag you once i raise it :-) thanks again
@megancooper @punjabimundaaa
Please help me to find out what's wrong with my code :(
if (activity.Type == ActivityTypes.Message)
{
try
{
// Sends user's Id and Name to RootDialog Class
StateClient stateClient = activity.GetStateClient();
BotData userData = await stateClient.BotState.GetUserDataAsync(activity.ChannelId, activity.From.Id);
userData.SetProperty<string>("UserId", activity.From.Id);
userData.SetProperty<string>("Name", activity.From.Name);
//other properties you want to set.
await stateClient.BotState.SetUserDataAsync(activity.ChannelId, activity.From.Id, userData);
await Conversation.SendAsync(activity, () => new Dialogs.SimpleLUISDialog());
}
catch (Exception ex)
{
string ss = ex.ToString();
}
}
else
{
HandleSystemMessage(activity);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
namespace MyBot.Dialogs
{
[Serializable]
[LuisModel("XXXX", "XXXX", domain: "westus.api.cognitive.microsoft.com", Staging = true)]
public class SimpleLUISDialog : LuisDialog<object>
{
[LuisIntent("")]
[LuisIntent("None")]
public async Task None(IDialogContext context, LuisResult result)
{
await context.PostAsync("I'm sorry. I didn't understand you.");
//context.Wait(MessageReceived);
}
}
}

hey Biren I assume the luis model and subscription id are correct and working. You can check on luis interface itself for the key/id combination and see if its working
Also try to see the actual http request sent from your app to Luis. Is there any request made?
a
@punjabimundaaa
I think the ID and key are fine.
I am able to get response from http request like below.
{
"query": "hello",
"topScoringIntent": {
"intent": "Greetings",
"score": 0.9118975
},
"intents": [
{
"intent": "Greetings",
"score": 0.9118975
},
{
"intent": "None",
"score": 0.123786092
},
{
"intent": "Name",
"score": 6.046063E-09
}
],
"entities": []
}