Search Unity

Monodevelop shows "Object Reference not set..." message during debug

Discussion in 'Formats & External Tools' started by MythicalCity, Feb 15, 2011.

  1. MythicalCity

    MythicalCity

    Joined:
    Feb 10, 2011
    Posts:
    420
    Not sure if anyone has noticed this, but with the new version of unity and monodevelop I have been playing around with watching some variables during debug (attach to process) and I notice that monodevelop will tell me that my Strings get an "Object Reference not set to an instance of an object" message, even though they work perfectly fine in my program. The strings are private and declared at the top of the class, and then are set in the Awake function:

    Code (csharp):
    1. private string myString;
    2.  
    3. void Awake()
    4. {
    5.      myString = "test";
    6. }
    I can still read back the script and there are no errors or warnings in Unity, so everything is working fine but I cannot inspect the variable in the monodevelop debugger. Also, any objects that use that use a string variable also give the above message which means I can't inspect any of the variables inside that object either. Crazy. Is this just a mono debugger bug?

    Also, this does not happen with other variables like Int and Float.
     
  2. jimmay

    jimmay

    Joined:
    Sep 23, 2010
    Posts:
    28
    I just started using the attach feature last night and noticed the same thing but with an object variable I had just allocated. Everything appears to work if I launch a new instance of Unity while debugging, so I suspect there is just some issue resolving the symbols in a running instance.

    Edit: I also forgot to mention that I had to connect to the Editor instance because I could not attach to the mono process. I'm on OSX.
     
    Last edited: Feb 16, 2011
  3. MythicalCity

    MythicalCity

    Joined:
    Feb 10, 2011
    Posts:
    420
    Yeah, I don't know what it is. I know that a String is actually a type of array of Chars, so it might be that the monodevelop debugger is really strict and wants you to set the number of chars with a new String(3) statement in your declaration? I don't know.
     
  4. jimmay

    jimmay

    Joined:
    Sep 23, 2010
    Posts:
    28
    eh, so actually this is happening when I hit 'debug' from monodevelop too. I thought it was just if I attached, but I must have still been on 3.1 the last time I started the debug from monodevelop. This is quite annoying.
     
  5. Matt_001

    Matt_001

    Joined:
    Sep 17, 2010
    Posts:
    101
    Same problem here! and it seems we are not alone with that issue. See that post.

    Also, if you try to print the length of your string inside the Watch window : "yourString.length" it will give you the correct value! Which is weird because the "yourString" variable has null reference according to MonoDev.
     
  6. jimmay

    jimmay

    Joined:
    Sep 23, 2010
    Posts:
    28
    Well, there is a work around but only if you still have access to the 3.1 version. I wiped 3.2, reinstalled 3.1 and copied monodevelop somewhere else. Wiped 3.1, installed 3.2 and deleted the monodevelop that comes with it. I put the 3.1 version in place and I can see the variables I am debugging now. Unfortunately, this doesn't have the attach feature that the new version has and it is probably missing other things too. Obviously do this at your own risk.
     
  7. MythicalCity

    MythicalCity

    Joined:
    Feb 10, 2011
    Posts:
    420
    Hmm, sounds like it's a bug with either unity 3.2 or the new monodevelop. I guess I will submit it as a bug.
     
  8. fabio di francesco

    fabio di francesco

    Joined:
    Jan 21, 2011
    Posts:
    2
    I tested some other types (custom classes, strings, arrays) and found that all reference types are not explorable by mono value watcher, instead all value types (int, float, struct) correctly shows their values. Reference type members can be watched only if value type. Probably some (*(ptr_to_some_value) in c++) feature is not yet well implemented in the debug watch tool, instead indirection to values works fine (-> in c++).
     
  9. Inouk

    Inouk

    Joined:
    Feb 16, 2011
    Posts:
    18
    Thanks for the idea, I am now running 2.4 on Unity 3.2. :) I'll see if it creates more problems than not.
     
  10. Matt_001

    Matt_001

    Joined:
    Sep 17, 2010
    Posts:
    101
    Indeed! You point out exactly where the problem probably is. However, it was working in the previous version of MonoDevelop (2.4), so I believe it is not something that haven't been implemented yet, but more something they broke during the new update process to 2.4.2 :)
     
  11. netatti

    netatti

    Joined:
    Feb 22, 2011
    Posts:
    5
    Hmm, this really sucks. I need to debug my stuff pretty urgently, so I'd appreciate any good news no this one.

    thanks!
     
  12. Matt_001

    Matt_001

    Joined:
    Sep 17, 2010
    Posts:
    101
    It is working fine for me! No more annoying bugs, I don't have the latest features though, but they doesn't worth it compare to those huge amount of bugs!
     
  13. jimmay

    jimmay

    Joined:
    Sep 23, 2010
    Posts:
    28
    Anyone know if this is fixed in 3.3? It would be nice to have the latest.
     
  14. jimmay

    jimmay

    Joined:
    Sep 23, 2010
    Posts:
    28
    I'll go ahead and answer this since I went ahead and took the plunge. It appears to be working fine with the latest drop, so woohoo! Now I can connect to a running instance and watch my variables.
     
  15. DaveA

    DaveA

    Joined:
    Apr 15, 2009
    Posts:
    310
    Not so fast. I had no problems with any version until Unity 3.4
     
  16. Siluetti

    Siluetti

    Joined:
    Sep 17, 2014
    Posts:
    1
    I had this problem ("monodevelop object reference not set to an instance of an object") with MonoDevelop (4.0.1) when I first started using it. My project name had spaces in it. I removed the spaces from the name, restarted both Unity and Monodevelop and suddenly they started working.

    Still, don't really know whether the problem was spaces in the name, as I moved the whole folder to another location.