1

I am developing an application which uses a chatbot. It will partly run on LUIS dataset that I have trained and partly on AIML, in case i don't have any relevant response.

Here is a piece of code from the file. I am basically trying to fetch entity type from LUIS and if it returns nothing, then trying to run AIML.

But it keeps throwing an unhandled exception: An unhandled exception of type 'System.ArgumentNullException' occurred in mscorlib.dll Additional information: Value cannot be null.

I have taken this AIML code from another project. Here's the link: https://github.com/Gr8z/ChatBotProject

Exception occurs in line: AimlBot.loadSettings();

Here's the stack trace of the exception:

at System.IO.Path.Combine(String path1,String path2) 
at AIMLbot.Bot.get_PathToConfigFiles();
at AIMLbot.Bot.loadSettings(String pathToSettings) 
at WDB.Chatbot.AIMLChatbot.Initialize() in
E:\WDB-master\WDB\manishChatBot.cs:line 229

And the source code:

#region LUIS Link
private string luisLink(string usrInput)
{
    string input = usrInput;
    string op = wb.DownloadString("https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/15c6bd2a-ecdc-41de-a054-0cce461e13a3?subscription-key=b72bdbb572fe4e90837647eb9c82b1c0&verbose=true&timezoneOffset=0&q=" + input);
    var jsonParse = JsonConvert.DeserializeObject<JClass>(op);

    if (jsonParse.entities.Count != 0)
    {
        entity = jsonParse.entities[0].type;
        return entity;
    }
    else
    {
        AIMLChatBot a = new AIMLChatBot();
        string aiml_response  = a.getOutput(input);
        return aiml_response;
    }
}
#endregion

#region AIML

public class AIMLChatBot
{
    const string UserId = "szabist";
    private Bot AimlBot;
    private User myUser;

    public AIMLChatBot()
    {
        AimlBot = new Bot();
        myUser = new User(UserId, AimlBot);
        Initialize();
    }

    // Loads all the AIML files in the \AIML folder         
    public void Initialize()
    {
        AimlBot.loadSettings(); //Exception on this line
        AimlBot.isAcceptingUserInput = false;
        AimlBot.loadAIMLFromFiles();
        AimlBot.isAcceptingUserInput = true;
    }

    // Given an input string, finds a response using AIMLbot lib
    public String getOutput(String input)
    {
        Request r = new Request(input, myUser, AimlBot);
        Result res = AimlBot.Chat(r);
        return (res.Output);
    }
}
#endregion
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
Ackermann47
  • 21
  • 1
  • 5
  • 1
    Please include the *complete* stack trace in your question. – Jon Skeet Apr 07 '18 at 07:55
  • Ok, I am showing the stack trace for Initialize Method: at System.IO.Path.Combine(String path1,String path2) at AIMLbot.Bot.get_PathToConfigFiles(); at AIMLbot.Bot.loadSettings(String pathToSettings) at WDB.Chatbot.AIMLChatbot.Initialize() in E:\WDB-master\WDB\manishChatBot.cs:line 229 – Ackermann47 Apr 07 '18 at 08:57
  • Please edit it into the question, instead of just putting it in comments. It looks like you should pass a path into that method though. (The lack of .NET naming conventions on the library makes me nervous about its quality, mind you.) – Jon Skeet Apr 07 '18 at 09:13
  • @DaisyShipton I have edited the Stack Trace in the code. Please don't mind the convention, it works fine in the original application but seems to give problems in mine. About passing a path, I have already done that in loadSettings() method but the exception persists. Any other suggestions? – Ackermann47 Apr 07 '18 at 13:52
  • Possible duplicate of [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Progman Apr 07 '18 at 17:05
  • I was hoping for an answer as per my context... Maybe this is a regular problem but I can't seem to point it out. I specify the path but still there is null pointer exception. Also it says mscorlib.dll file has the exception. Can someone tell me where I can find it, or just anything regarding configuration file related to aiml – Ackermann47 Apr 07 '18 at 17:09
  • It's not actually a duplicate, because it's not a `NullReferenceException` or a `NullPointerException` - it's an `ArgumentNullException`, which is not the same thing. – Jon Skeet Apr 07 '18 at 18:26
  • "Please don't mind the convention, it works fine in the original application but seems to give problems in mine." What do you mean by that? Following idiomatic naming conventions really, really shouldn't cause problems, but not following them makes for worse questions, because the code is distractingly "different" – Jon Skeet Apr 07 '18 at 18:28
  • Your stack trace seems to contradict your code - you're calling the parameterless method, but the parameterized method is in the stack trace. Could you clarify which version of AIMLbot you're using? The last one I could find was from 2007 - if you've got any option of using a rather more modern (and idiomatic) library, I would do so. – Jon Skeet Apr 07 '18 at 18:35
  • @Daisy Shipton I am really sorry about that naming convention. The source is ambiguous. Also the method is overloaded to take single parameter. In shivamsom's answer you can see how it looks like – Ackermann47 Apr 07 '18 at 18:39
  • @Ackermann47: Yes, I know it's overloaded - but you're calling it without any arguments, but the parameterized version is in the stack trace. This may just be the JIT compiler. Are you running this in a debugger? (If you do, you're likely to get a more accurate stack trace.) Again, having looked at some of this code, it doesn't seem to be quality code I'd want to rely on - if you've got *any* other option, I'd use it. (I appreciate you may not have.) – Jon Skeet Apr 07 '18 at 18:43
  • @Daisy Shipton For now, this is all I have but now that this is worthless I will look for some other way. Thanks for your time and effort. I really appreciate it. PS: I was running this on visual studio. – Ackermann47 Apr 08 '18 at 04:51

2 Answers2

2

I followed the given link: https://github.com/Gr8z/ChatBotProject and downloaded the AIMLBot.dll file which has the implementation of the method AimlBot.loadSettings();.

On personally DE-Compiling the file, I found the implementation which looks something like this:

enter image description here

So, what I suggest is to check whether you have config/Settings.xml file in your ../bin/Debug/ or the directory where your program resides.

The program is unable to find the location of that file because of which it gives you a Null Argument Exception.

Shivam Som
  • 142
  • 1
  • 8
  • The stack trace doesn't show the parameterless method - it's the `loadSettings(string)` method - and it's within the `PathToConfigFiles` property. – Jon Skeet Apr 07 '18 at 18:30
  • (I've tried looking there, but I can't see why that would end up with the ArgumentNullException we're seeing. It's pretty old and horrible code though.) – Jon Skeet Apr 07 '18 at 18:38
  • Exactly right. It is overloaded to take 1 parameter. – Ackermann47 Apr 07 '18 at 18:43
  • @Daisy Shipton Can you provide me with a more updated and convention friendly code? It seems like this code is in fact worthless – Ackermann47 Apr 07 '18 at 18:45
  • @Ackermann47: I don't know anything about AIML, so I don't know what else would provide similar functionality. (But I agree that it would be worth abandoning this.) – Jon Skeet Apr 07 '18 at 18:46
  • Actually the `loadSettings` method is an overloaded method. I'm sorry, i couldn't attach the screenshot for the same.The execution is `Intialize()` calls the `loadSettings()` which in turn calls its overloaded method `loadSettings(string)`. – Shivam Som Apr 07 '18 at 19:04
0

As @Shivam Som has shown, the method needs one argument which specifies the location of settings.

In order to solve this issue, you need to copy your config folder which contains AIML settings to the Debug folder where the C# application runs.

In case you don't have the necessary files for AIML configuration, you can download them by going to https://www.effacestudios.com/wp-content/uploads/2018/04/AIMLBot.zip

Dharman
  • 30,962
  • 25
  • 85
  • 135
s3m3dov
  • 11
  • 2