Error tutorial of MR and Azure 303: Natural language understanding (LUIS) - Object reference not set to an instance of an object

Ines 1 Reputation point
2020-09-29T17:05:05.793+00:00

I followed the tutorial of MR and Azure 303: Natural language understanding (LUIS) https://learn.microsoft.com/en-us/windows/mixed-reality/develop/unity/tutorials/mr-azure-303
In the end, I ended up getting an error on Unity that says

'"Luis Request Exception Message: Object reference not set to an instance of an object
UnityEngine.Debug:Log(Object)
<SubmitRequestToLuis>d__6:MoveNext() (at Assets/Scripts/LuisManager.cs:76)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)"

I am using a newer version of Unity, could that be the problem ?

My messages are actually showing up on the LUIS portal, so i dont think there's a problem with the endpoint link.

This is the full luisManager code

using System;  
using System.Collections;  
using System.Collections.Generic;  
using System.IO;  
using UnityEngine;  
using UnityEngine.Networking;  
  
public class LuisManager : MonoBehaviour  
{  
    public static LuisManager instance;  
  
    //Substitute the value of luis Endpoint with your own End Point  
  
    string luisEndpoint = "https://luisinestest.cognitiveservices.azure.com/luis/prediction/v3.0/apps/6d954c3f-9063-4567-8bd8-196a6d1f3171/slots/production/predict?subscription-key=271f533a70fc45dba93d0b4fd8fc2842&verbose=true&show-all-intents=true&log=true&query=";  
  
    [Serializable] //this class represents the LUIS response  
    public class AnalysedQuery  
    {  
        public TopScoringIntentData topScoringIntent;  
        public EntityData[] entities;  
        public string query;  
    }  
  
    // This class contains the Intent LUIS determines   
    // to be the most likely  
    [Serializable]  
    public class TopScoringIntentData  
    {  
        public string intent;  
        public float score;  
    }  
  
    // This class contains data for an Entity  
    [Serializable]  
    public class EntityData  
    {  
        public string entity;  
        public string type;  
        public int startIndex;  
        public int endIndex;  
        public float score;  
    }  
  
    private void Awake()  
    {  
        // allows this class instance to behave like a singleton  
        instance = this;  
    }  
  
    /// <summary>  
    /// Call LUIS to submit a dictation result.  
    /// The done Action is called at the completion of the method.  
    /// </summary>  
    public IEnumerator SubmitRequestToLuis(string dictationResult, Action done)  
    {  
        string queryString = string.Concat(Uri.EscapeDataString(dictationResult));  
  
        using (UnityWebRequest unityWebRequest = UnityWebRequest.Get(luisEndpoint + queryString))  
        {  
            yield return unityWebRequest.SendWebRequest();  
  
            if (unityWebRequest.isNetworkError || unityWebRequest.isHttpError)  
            {  
                Debug.Log(unityWebRequest.error);  
            }  
            else  
            {  
                try  
                {  
                    AnalysedQuery analysedQuery = JsonUtility.FromJson<AnalysedQuery>(unityWebRequest.downloadHandler.text);  
  
                    //analyse the elements of the response   
                    AnalyseResponseElements(analysedQuery);  
                }  
                catch (Exception exception)  
                {  
                    Debug.Log("Luis Request Exception Message: " + exception.Message);  
                }  
            }  
  
            done();  
            yield return null;  
        }  
    }  
  
  
    private void AnalyseResponseElements(AnalysedQuery aQuery)  
    {  
        string topIntent = aQuery.topScoringIntent.intent;  
  
        // Create a dictionary of entities associated with their type  
        Dictionary<string, string> entityDic = new Dictionary<string, string>();  
  
        foreach (EntityData ed in aQuery.entities)  
        {  
            entityDic.Add(ed.type, ed.entity);  
        }  
  
        // Depending on the topmost recognized intent, read the entities name  
        switch (aQuery.topScoringIntent.intent)  
        {  
            case "ChangeObjectColor":  
                string targetForColor = null;  
                string color = null;  
  
                foreach (var pair in entityDic)  
                {  
                    if (pair.Key == "target")  
                    {  
                        targetForColor = pair.Value;  
                    }  
                    else if (pair.Key == "color")  
                    {  
                        color = pair.Value;  
                    }  
                }  
  
                Behaviours.instance.ChangeTargetColor(targetForColor, color);  
                break;  
  
            case "ChangeObjectSize":  
                string targetForSize = null;  
                foreach (var pair in entityDic)  
                {  
                    if (pair.Key == "target")  
                    {  
                        targetForSize = pair.Value;  
                    }  
                }  
  
                if (entityDic.ContainsKey("upsize") == true)  
                {  
                    Behaviours.instance.UpSizeTarget(targetForSize);  
                }  
                else if (entityDic.ContainsKey("downsize") == true)  
                {  
                    Behaviours.instance.DownSizeTarget(targetForSize);  
                }  
                break;  
        }  
    }  
  
     
}  
  
Azure DevTest Labs
Azure DevTest Labs
An Azure service that is used for provisioning development and test environments.
278 questions
Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
2,901 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.