{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/BotBuilder/issues/3155","repository_url":"https://api.github.com/repos/Microsoft/BotBuilder","labels_url":"https://api.github.com/repos/Microsoft/BotBuilder/issues/3155/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/BotBuilder/issues/3155/comments","events_url":"https://api.github.com/repos/Microsoft/BotBuilder/issues/3155/events","html_url":"https://github.com/Microsoft/BotBuilder/issues/3155","id":243782703,"number":3155,"title":"[Question] context.Forward() causes stack exception?","user":{"login":"megancooper","id":8683055,"avatar_url":"https://avatars1.githubusercontent.com/u/8683055?v=4","gravatar_id":"","url":"https://api.github.com/users/megancooper","html_url":"https://github.com/megancooper","followers_url":"https://api.github.com/users/megancooper/followers","following_url":"https://api.github.com/users/megancooper/following{/other_user}","gists_url":"https://api.github.com/users/megancooper/gists{/gist_id}","starred_url":"https://api.github.com/users/megancooper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/megancooper/subscriptions","organizations_url":"https://api.github.com/users/megancooper/orgs","repos_url":"https://api.github.com/users/megancooper/repos","events_url":"https://api.github.com/users/megancooper/events{/privacy}","received_events_url":"https://api.github.com/users/megancooper/received_events","type":"User","site_admin":false},"labels":[{"id":429202671,"url":"https://api.github.com/repos/Microsoft/BotBuilder/labels/.NET%20SDK","name":".NET SDK","color":"1d76db","default":false},{"id":622541392,"url":"https://api.github.com/repos/Microsoft/BotBuilder/labels/dialogs","name":"dialogs","color":"fbca04","default":false},{"id":335881076,"url":"https://api.github.com/repos/Microsoft/BotBuilder/labels/question","name":"question","color":"b60205","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-07-18T16:53:10Z","updated_at":"2017-07-19T15:59:51Z","closed_at":null,"body":"<!-- Have a question? Please ask it on http://stackoverflow.com/questions/tagged/botframework -->\r\n\r\n## System Information (Required)\r\n* SDK Language: .NET/C# \r\n* SDK Version: 4.6\r\n* Development Environment: LOCALHOST\r\n\r\n## Issue Description\r\nI am using the AuthBot to try to authenticate users on my Bot. Whenever I call:\r\n`await context.Forward(new AzureAuthDialog(AuthSettings.Scopes), this.ResumeAfterAuth, result, CancellationToken.None);`\r\n\r\n I get the following error in my code:\r\n![errrrr](https://user-images.githubusercontent.com/8683055/28329243-c7a1c9a6-6bae-11e7-8ea5-e633ee5fd130.PNG)\r\n\r\n\r\n\r\n## Code Sample\r\nHere is the Luis Intent function, (and helper function), that is supposed to help someone login:\r\n\r\n       `\r\n        [LuisIntent(\"Login\")]\r\n        public async Task Login(IDialogContext context, LuisResult result)\r\n        {\r\n\r\n            if (string.IsNullOrEmpty(await context.GetAccessToken(AuthSettings.Scopes)))\r\n            {\r\n                await context.PostAsync($\"You must log in!\");\r\n\r\n                await context.Forward(new AzureAuthDialog(AuthSettings.Scopes), this.ResumeAfterAuth, result, CancellationToken.None);\r\n            }\r\n            else\r\n            {\r\n                var accessToken = await context.GetAccessToken(AuthSettings.Scopes);\r\n\r\n                await context.PostAsync($\"You are already logged in. Here is your token: {accessToken} \");\r\n            }\r\n        }\r\n\r\n        private async Task ResumeAfterAuth(IDialogContext context, IAwaitable<string> result)\r\n        {\r\n            var message = await result;\r\n\r\n            await context.PostAsync(message);\r\n        }\r\n`\r\n\r\nMy MessagesController.cs Class:\r\n\r\n\r\n```\r\n    [BotAuthentication]\r\n    public class MessagesController : ApiController\r\n    {\r\n        [BotAuthentication]\r\n        public async Task<HttpResponseMessage> Post([FromBody]Activity activity)\r\n        {\r\n            \r\n            if (activity != null && activity.Type == ActivityTypes.Message)\r\n            {\r\n                // Strip any @mentions\r\n                Mention[] m = activity.GetMentions();\r\n                for (int x = 0; x < m.Length; x++)\r\n                {\r\n                    if (m[x].Mentioned.Id == activity.Recipient.Id)\r\n                    {\r\n                        if (m[x].Text != null)\r\n                        {\r\n                            activity.Text = activity.Text.Replace(m[x].Text, \"\");\r\n                        }\r\n                    }\r\n                }\r\n\r\n                // Sends user's Id and Name to RootDialog Class\r\n                StateClient stateClient = activity.GetStateClient();\r\n                BotData userData = await stateClient.BotState.GetUserDataAsync(activity.ChannelId, activity.From.Id);\r\n                userData.SetProperty<string>(\"UserId\", activity.From.Id);\r\n                userData.SetProperty<string>(\"Name\", activity.From.Name);\r\n\r\n                // send these values in the Context\r\n                await stateClient.BotState.SetUserDataAsync(activity.ChannelId, activity.From.Id, userData);\r\n                // RootDialog() is the LUIS dialog class\r\n                await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());\r\n\r\n            }\r\n            else\r\n            {\r\n                await HandleSystemMessage(activity);\r\n            }\r\n\r\n            var response = Request.CreateResponse(HttpStatusCode.OK);\r\n            return response;\r\n        }\r\n    }\r\n```\r\n\r\nHere are the packages I'm using (packages.config):\r\n\r\n```\r\n<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<packages>\r\n  <package id=\"AuthBot\" version=\"3.6.5-alpha\" targetFramework=\"net46\" />\r\n  <package id=\"Autofac\" version=\"4.6.0\" targetFramework=\"net46\" />\r\n  <package id=\"Chronic.Signed\" version=\"0.3.2\" targetFramework=\"net46\" />\r\n  <package id=\"Microsoft.AspNet.WebApi\" version=\"5.2.3\" targetFramework=\"net46\" />\r\n  <package id=\"Microsoft.AspNet.WebApi.Client\" version=\"5.2.3\" targetFramework=\"net46\" />\r\n  <package id=\"Microsoft.AspNet.WebApi.Core\" version=\"5.2.3\" targetFramework=\"net46\" />\r\n  <package id=\"Microsoft.AspNet.WebApi.WebHost\" version=\"5.2.3\" targetFramework=\"net46\" />\r\n  <package id=\"Microsoft.Bot.Builder\" version=\"3.8.5.0\" targetFramework=\"net46\" />\r\n  <package id=\"Microsoft.IdentityModel.Protocol.Extensions\" version=\"1.0.4.403061554\" targetFramework=\"net46\" />\r\n  <package id=\"Microsoft.IdentityModel.Tokens\" version=\"5.1.3\" targetFramework=\"net46\" />\r\n  <package id=\"Microsoft.Rest.ClientRuntime\" version=\"2.3.7\" targetFramework=\"net46\" />\r\n  <package id=\"Microsoft.Win32.Primitives\" version=\"4.0.1\" targetFramework=\"net46\" />\r\n  <package id=\"Microsoft.WindowsAzure.ConfigurationManager\" version=\"3.2.3\" targetFramework=\"net46\" />\r\n  <package id=\"Newtonsoft.Json\" version=\"10.0.2\" targetFramework=\"net46\" />\r\n  <package id=\"System.Collections\" version=\"4.0.11\" targetFramework=\"net46\" />\r\n  <package id=\"System.Collections.Concurrent\" version=\"4.0.12\" targetFramework=\"net46\" />\r\n  <package id=\"System.Diagnostics.Debug\" version=\"4.0.11\" targetFramework=\"net46\" />\r\n  <package id=\"System.Diagnostics.DiagnosticSource\" version=\"4.0.0\" targetFramework=\"net46\" />\r\n  <package id=\"System.Globalization\" version=\"4.0.11\" targetFramework=\"net46\" />\r\n  <package id=\"System.IdentityModel.Tokens.Jwt\" version=\"4.0.4.403061554\" targetFramework=\"net46\" />\r\n  <package id=\"System.IO\" version=\"4.1.0\" targetFramework=\"net46\" />\r\n  <package id=\"System.Linq\" version=\"4.1.0\" targetFramework=\"net46\" />\r\n  <package id=\"System.Net.Http\" version=\"4.0.0\" targetFramework=\"net46\" />\r\n  <package id=\"System.Net.Primitives\" version=\"4.0.11\" targetFramework=\"net46\" />\r\n  <package id=\"System.Reflection\" version=\"4.1.0\" targetFramework=\"net46\" />\r\n  <package id=\"System.Reflection.Extensions\" version=\"4.0.1\" targetFramework=\"net46\" />\r\n  <package id=\"System.Runtime\" version=\"4.1.0\" targetFramework=\"net46\" />\r\n  <package id=\"System.Runtime.Extensions\" version=\"4.1.0\" targetFramework=\"net46\" />\r\n  <package id=\"System.Runtime.InteropServices\" version=\"4.1.0\" targetFramework=\"net46\" />\r\n  <package id=\"System.Runtime.Serialization.Json\" version=\"4.0.2\" targetFramework=\"net46\" />\r\n  <package id=\"System.Runtime.Serialization.Primitives\" version=\"4.1.1\" targetFramework=\"net46\" />\r\n  <package id=\"System.Security.Cryptography.Algorithms\" version=\"4.2.0\" targetFramework=\"net46\" />\r\n  <package id=\"System.Security.Cryptography.Encoding\" version=\"4.0.0\" targetFramework=\"net46\" />\r\n  <package id=\"System.Security.Cryptography.Primitives\" version=\"4.0.0\" targetFramework=\"net46\" />\r\n  <package id=\"System.Security.Cryptography.X509Certificates\" version=\"4.1.0\" targetFramework=\"net46\" />\r\n  <package id=\"System.Text.Encoding\" version=\"4.0.11\" targetFramework=\"net46\" />\r\n  <package id=\"System.Text.Encoding.Extensions\" version=\"4.0.11\" targetFramework=\"net46\" />\r\n  <package id=\"System.Text.RegularExpressions\" version=\"4.1.0\" targetFramework=\"net46\" />\r\n  <package id=\"System.Threading\" version=\"4.0.11\" targetFramework=\"net46\" />\r\n  <package id=\"System.Threading.Tasks\" version=\"4.0.11\" targetFramework=\"net46\" />\r\n  <package id=\"System.Xml.ReaderWriter\" version=\"4.0.11\" targetFramework=\"net46\" />\r\n  <package id=\"System.Xml.XDocument\" version=\"4.0.11\" targetFramework=\"net46\" />\r\n</packages>\r\n```\r\n\r\n## Expected Behavior\r\nAn authentication card will popup\r\n\r\n## Actual Results\r\n \"text\": \"Exception: Stack is empty\",\r\n  \"attachments\": [\r\n    {\r\n      \"contentType\": \"text/plain\",\r\n      \"content\": \"   at Microsoft.Bot.Builder.Internals.Fibers.Extensions.Peek[T](IReadOnlyList`1 stack)\\r\\n   at \r\n       .... ETC....)\r\n"},"comment":{"url":"https://api.github.com/repos/Microsoft/BotBuilder/issues/comments/316433860","html_url":"https://github.com/Microsoft/BotBuilder/issues/3155#issuecomment-316433860","issue_url":"https://api.github.com/repos/Microsoft/BotBuilder/issues/3155","id":316433860,"user":{"login":"megancooper","id":8683055,"avatar_url":"https://avatars1.githubusercontent.com/u/8683055?v=4","gravatar_id":"","url":"https://api.github.com/users/megancooper","html_url":"https://github.com/megancooper","followers_url":"https://api.github.com/users/megancooper/followers","following_url":"https://api.github.com/users/megancooper/following{/other_user}","gists_url":"https://api.github.com/users/megancooper/gists{/gist_id}","starred_url":"https://api.github.com/users/megancooper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/megancooper/subscriptions","organizations_url":"https://api.github.com/users/megancooper/orgs","repos_url":"https://api.github.com/users/megancooper/repos","events_url":"https://api.github.com/users/megancooper/events{/privacy}","received_events_url":"https://api.github.com/users/megancooper/received_events","type":"User","site_admin":false},"created_at":"2017-07-19T15:59:51Z","updated_at":"2017-07-19T15:59:51Z","body":"@JasonSowers I figured out the issue. I needed to add these lines to my Global.asax.cs file:\r\n```\r\n            AuthSettings.Mode = ConfigurationManager.AppSettings[\"ActiveDirectory.Mode\"];\r\n            AuthSettings.EndpointUrl = ConfigurationManager.AppSettings[\"ActiveDirectory.EndpointUrl\"];\r\n            AuthSettings.Tenant = ConfigurationManager.AppSettings[\"ActiveDirectory.Tenant\"];\r\n            AuthSettings.RedirectUrl = ConfigurationManager.AppSettings[\"ActiveDirectory.RedirectUrl\"];\r\n            AuthSettings.ClientId = ConfigurationManager.AppSettings[\"ActiveDirectory.ClientId\"];\r\n            AuthSettings.ClientSecret = ConfigurationManager.AppSettings[\"ActiveDirectory.ClientSecret\"];\r\n```"}}
{"actor":{"display_login":"megancooper"}}