Search Unity

Porting a .net to unity: NullReferenceException: Object reference not set to an instance of an objec

Discussion in 'Scripting' started by Slarti-42, Jan 16, 2020.

  1. Slarti-42

    Slarti-42

    Joined:
    Jul 1, 2019
    Posts:
    25
    Hi folks,

    I have a running .net program, that works on console. Now I want to port it over and I am kinda a newbie in Unity.
    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    Here is the code:

    This script is the entry point and is attached to an empty GameObject in the editor:
    Code (CSarp):
    1.  
    2. using UnityEngine;
    3. namespace QuickstartClient
    4. {
    5.    
    6.     public class Test : MonoBehaviour
    7.     {
    8.         // Start is called before the first frame update
    9.         void Start()
    10.         {
    11.             QuickStart.SubscribeQAUpdate();
    12.         }
    13.         // Update is called once per frame
    14.         void Update()
    15.         {
    16.         }
    17.     }
    18. }
    19.  
    and it calls that function in the class QuickStart:
    Code (CSharp):
    1.  
    2. namespace QuickstartClient
    3. {
    4.      private static LServer ls;
    5.      class QuickStart : MonoBehavior
    6.      {
    7.         public static void SubscribeQAUpdate()
    8.         {
    9.             Debug.Log("... Starting Subscription!");
    10.  
    11.             Subscription qa_updates = new Subscription("MERGE");
    12.             qa_updates.Fields = new string[7] { "timestamp", "message", };
    13.             qa_updates.Items = new string[1] { "QA-Updater" };
    14.             qa_updates.addListener(new QA_Listener());
    15.  
    16.             Debug.Log("... " + qa_updates.Fields[0]);
    17.            ls.subscribe(qa_updates); \\------>Error
    18.  
    19.             Debug.Log("... Starting Subscription done!");
    20.             }
    21.  
    ls.subscribe is from a .dll and the fileds are not empty.

    Please, what should I do?
    Thanks,Slarti
     
    Last edited: Jan 16, 2020
  2. _met44

    _met44

    Joined:
    Jun 1, 2013
    Posts:
    551
    Where does "ls" come from ?
     
  3. Slarti-42

    Slarti-42

    Joined:
    Jul 1, 2019
    Posts:
    25
    Code (CSharp):
    1. namespace QuickstartClient
    2. {
    3.      private static LServer ls;
    4.      class QuickStart : MonoBehavior
    5.      {
    6.         public static void SubscribeQAUpdate()
    7. ...
    8.  

    and this is an external .dll that works.

    must have dropped out by editing. I re-edited the post
     
  4. _met44

    _met44

    Joined:
    Jun 1, 2013
    Posts:
    551
    ok then you have to instantiate this somewhere / somehow dont you ?
     
  5. Slarti-42

    Slarti-42

    Joined:
    Jul 1, 2019
    Posts:
    25
    :rolleyes::oops:
    Oh gees ... yes thanks.

    ls = new LServer(x, y);

    Thanks for helping a nooby
     
    _met44 likes this.
unityunity