microsoft / Cognitive-LUIS-Windows

Windows (.Net) SDK for the Microsoft Language Understanding Intelligent Service API, part of Congitive Services
www.microsoft.com/cognitive-services/en-us/language-understanding-intelligent-service-luis
Other
134 stars 78 forks source link

Null Reference Exception if result["topScoringIntent"] doesn't exist #11

Closed ChuckkNorris closed 8 years ago

ChuckkNorris commented 8 years ago

In LuisResult.Load(), if JToken result["topScoringIntent"] does not exist (which it did not in my case - not sure why), Intent.Load() will throw a null reference exception.

LuisResult.Load() requires a null check of the topScoringIntent:

if (Intents.Length == 0)
{
    JObject topScoringIntent = (JObject)result["topScoringIntent"];
    if (topScoringIntent != null) {
        var t = new Intent();
        t.Load(topScoringIntent);
        TopScoringIntent = t;
        Intents = new Intent[1];
        Intents[0] = TopScoringIntent;
    }
}
ChuckkNorris commented 8 years ago

Update: The root cause was that the app had not been published yet - perhaps a better solution would be to throw an exception stating that the "LUIS App need to be published" if the topScoringIntent is null.

tachyons commented 8 years ago

topScoringIntent will be present only if you are using preview mode , it does not exist in production

ChuckkNorris commented 8 years ago

@tachyons Negative - it does exist. As stated, after I published my LUIS App, the topScoringIntent was populated just fine. The issue is that the LUIS C# SDK will throw a null reference exception if the app isn't published rather than notifying the developer that the app needs to be published first.

Ahmkel commented 8 years ago

Fixed in latest commit