Bug 21232 - Debugger showing variables as null
Summary: Debugger showing variables as null
Status: RESOLVED DUPLICATE of bug 25358
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: Debugger ()
Version: 5.1
Hardware: Macintosh Mac OS
: High normal
Target Milestone: master
Assignee: Jeffrey Stedfast
Depends on:
Reported: 2014-07-10 09:21 UTC by Paul Johnson
Modified: 2015-01-07 00:40 UTC (History)
4 users (show)

Is this bug a regression?: ---
Last known good build:

Video showing the bug in action (260.20 KB, application/zip)
2014-07-11 07:05 UTC, Paul Johnson

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Paul Johnson 2014-07-10 09:21:54 UTC
I have a class defined outside of an if condition. Call it outsideClass for this. The class is populated with data (doesn't matter what the class is)

If I have

if (foo)
  // something
  var insideClass = outsideClass;
  insideClass.foo = 10;
  insideClass.bar = "20";
  Console.WriteLine("foo = {0}, bar = {1}", foo, bar);

the code in else will compile and execute fine, however, if you try to inspect the values for insideClass, insideClass reports as being null.

The same null is seen if you explicitly create an instance of outsideClass type and assign that to the outside class and operate on that new instance viz

  var insideClass = outsideClassDef();
  insideClass = outsideClass;

Using XS
Comment 1 Ram Chandra 2014-07-11 06:48:17 UTC
I tried this issue but I am unable to reproduce this issue

Steps I followed:

1. Open a console application on XS.
2.  Write the following code on "Program.cs" 

    class Demo
        public static void Main()
            outsideClass oc = new outsideClass();

    class outsideClass
        public int foo { get; set; }
        public string bar { get; set; }
        public void CreateObjectOfNestedClass()

            if (false)
                // something
                var insideClass = new outsideClass();
                insideClass.foo = 10;
                insideClass.bar = "20";
                Console.WriteLine("foo = {0}, bar = {1}", insideClass.foo, insideClass.bar);

When I debug my application I observed that the value of insideClass is not null. It contains two property "foo" and "bar".

Screencast: http://www.screencast.com/t/zvDRlJPKG

Please let me know if I am missing anything?

Environment Info:

Mac OS X 10.9.3
Xamarin Studio: 5.1.2 (build 0)
Build Information 

Release ID: 501020000
Git revision: 4574b1e5cf09f2e95e486c259bd9267a68c77cb3
Build date: 2014-07-02 20:50:40-04
Xamarin addins: fdea6fe3e36cda39291b39c81133e409c6d6f092
Comment 2 Paul Johnson 2014-07-11 07:05:31 UTC
Created attachment 7335 [details]
Video showing the bug in action
Comment 3 Ram Chandra 2014-07-11 07:38:39 UTC
Thanks Pual

I have seen your video, but nothing is clear in video. Its totally blur, I have tried using flv player and vlc player, but I am not able to understand what is happening in video. 

Screencast : http://www.screencast.com/t/rTQCEiuoE

Can we please have a clear video or test sample to demonstrate the issue?
Comment 4 Paul Johnson 2014-07-11 08:43:52 UTC

Hope that makes it clearer.

mb is clearly instantiated at the start of the else block and then assigned to currentMob. If the instance had not been created, then the app would have fallen over at this point. As it is accepting currentMob, I can only conclude that the debugger is not playing ball
Comment 5 David Karlaš 2015-01-07 00:40:08 UTC
This is mcs bug

*** This bug has been marked as a duplicate of bug 25358 ***