Asp.net mvc 在asp.net MVC中设置AIML(FormatException错误)

Asp.net mvc 在asp.net MVC中设置AIML(FormatException错误),asp.net-mvc,aiml,Asp.net Mvc,Aiml,当谈到使用AIML和为asp.net mvc网页设置AIML时,完全没有必要。我有一个基本的视图设置,用户可以在文本框中输入消息,我正试图让聊天机器人返回响应。我已经获得了与我的文本案例的交互,因此我知道该函数正确地获取了用户响应,并且我可以发回响应并在聊天框中显示,我的问题是尝试设置聊天机器人以创建动态响应。现在,在我的控制器中,我有: String filePath = Server.MapPath("~/aimlBot/aiml/"); ChatBot catbot = n

当谈到使用AIML和为asp.net mvc网页设置AIML时,完全没有必要。我有一个基本的视图设置,用户可以在文本框中输入消息,我正试图让聊天机器人返回响应。我已经获得了与我的文本案例的交互,因此我知道该函数正确地获取了用户响应,并且我可以发回响应并在聊天框中显示,我的问题是尝试设置聊天机器人以创建动态响应。现在,在我的控制器中,我有:

    String filePath = Server.MapPath("~/aimlBot/aiml/");
    ChatBot catbot = new ChatBot(filePath);
    string ReturnText = catbot.GetOutput(text); //text is just a string no html or fancy stuff in it
还有我的聊天机器人课

    Public class ChatBot : Bot
    {
        private Bot myBot;
        private User myUser;

        public ChatBot(string filepath)
        {
            myBot = new Bot();
            myUser = new User("Human", myBot);
            Initialize(filepath);
        }

        private void Initialize(string filepath)
        {
            AIMLbot.Utils.AIMLLoader loader = new AIMLbot.Utils.AIMLLoader(this.myBot);
            myBot.isAcceptingUserInput = false;
            loader.loadAIML(filepath);          
            myBot.isAcceptingUserInput = true;
        }

        public String GetOutput(String input)
        {
            Request r = new Request(input, myUser, myBot);
            Result res = myBot.Chat(r); //breaks here
            string response = "Bot: " + res.Output;
            return (response);
        }
    }
我遇到的问题是 Result res=myBot.Chat(r); 程序抛出一个格式化异常

    System.FormatException was unhandled by user code
    Message=Input string was not in a correct format.
    Source=mscorlib
    StackTrace:
    at System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)
    at System.Convert.ToDouble(String value)
    at AIMLbot.Bot.get_TimeOut()
    at AIMLbot.Utils.Node.evaluate(String path, SubQuery query, Request request, MatchState matchstate, StringBuilder wildcard)
    at AIMLbot.Bot.Chat(Request request)
    at Ira.aimlBot.ChatBot.GetOutput(String input) in C:\Users\Ira\Documents\Visual Studio 2010\Projects\Ira\Ira\aimlBot\ChatBot.cs:line 36
    at Ira.Controllers.ARGController.Speak(String text) in C:\Users\Ira\Documents\Visual Studio 2010\Projects\Ira\Ira\Controllers\ARGController.cs:line 35
    at lambda_method(Closure , ControllerBase , Object[] )
    at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
    at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
    at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
    at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
    at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
    InnerException: 
用户代码未处理System.FormatException Message=输入字符串的格式不正确。 Source=mscorlib 堆栈跟踪: 在System.Number.ParseDouble(字符串值、NumberStyles选项、NumberFormatInfo numfmt) at System.Convert.ToDouble(字符串值) 在AIMLbot.Bot.get_TimeOut()上 在AIMLbot.Utils.Node.evaluate(字符串路径、子查询查询、请求请求、匹配状态、匹配状态、StringBuilder通配符) 在AIMLbot.Bot.Chat(请求) 在C:\Users\Ira\Documents\VisualStudio2010\Projects\Ira\Ira\aimlBot\ChatBot.cs中的Ira.aimlBot.ChatBot.GetOutput(字符串输入):第36行 在C:\Users\Ira\Documents\visualstudio 2010\Projects\Ira\Ira\Controllers\ARGController.cs中的Ira.Controllers.ARGController.Speak(字符串文本):第35行 在lambda_方法中(闭包、控制器基、对象[]) 位于System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller,Object[]参数) 位于System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext ControllerContext,IDictionary`2参数) 位于System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext ControllerContext,ActionDescriptor ActionDescriptor,IDictionary`2参数) 在System.Web.Mvc.ControllerActionInvoker.c_uuDisplayClass15.b_uuu12()中 位于System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter筛选器、ActionExecutingContext预文本、Func`1 continuation) 内部异常:
我不知道我的代码出了什么问题。我甚至尝试过将其从变量字符串更改为硬代码大小写,如“Hello how are you”,这仍然会导致相同的异常

除了loadSettings功能外,您的一切都很完美。请参阅下面的代码片段以清除您的问题

public ChatBot(string filepath)
{
            myBot = new Bot();
            myBot.loadSettings(); // <----- You have to insert this line to fix the error!
            myUser = new User("Human", myBot);
            Initialize(filepath);
}
公共聊天机器人(字符串文件路径) { myBot=新Bot(); myBot.loadSettings()//