Bug 17259 - "this" is null in a superclass constructor but this.<property> resolves
Summary: "this" is null in a superclass constructor but this.<property> resolves
Status: RESOLVED INVALID
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 7.0.5.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-01-15 15:41 UTC by michael.yohe
Modified: 2014-01-15 15:47 UTC (History)
1 user (show)

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


Attachments
Shows that "this.NodeType" resolves (in the actual code) (33.26 KB, image/png)
2014-01-15 15:42 UTC, michael.yohe
Details
Shows the debugger show NullReferenceException when evaluating object o = this (42.88 KB, image/png)
2014-01-15 15:43 UTC, michael.yohe
Details
Shows the debugger with NullReferenceException when evaluating "this" (42.85 KB, image/png)
2014-01-15 15:44 UTC, michael.yohe
Details
Shows the actual NullReferenceException because "this" is null (107.11 KB, image/png)
2014-01-15 15:45 UTC, michael.yohe
Details


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:
Status:
RESOLVED INVALID

Description michael.yohe 2014-01-15 15:41:41 UTC
I am observing very strange behavior using Xamarin iOS 7.0.5.  The comments in example code help explain the problem.

Take for example the following:

abstract class Foo
{
   private readonly int i;
   private readonly int j;

   protected Foo(int first, int second)
   {
      // this.i resolves properly
      this.i = first;
      // this.j resolves properly
      this.j = second;

      // here is the problem
      // o will be null because "this" is null
      object o = this;

      // this will throw a NullReferenceException
      // debugger also shows NullReferenceException when evaluating "this" and "o"
      Console.WriteLine(o.ToString());
   }
}

// inherited class
public class Bar : Foo
{
   Bar()
     // here is the base constructor
     : base(1, 2)
   {

   }
}
Comment 1 michael.yohe 2014-01-15 15:42:23 UTC
Created attachment 5846 [details]
Shows that "this.NodeType" resolves (in the actual code)
Comment 2 michael.yohe 2014-01-15 15:43:24 UTC
Created attachment 5847 [details]
Shows the debugger show NullReferenceException when evaluating object o = this
Comment 3 michael.yohe 2014-01-15 15:44:18 UTC
Created attachment 5848 [details]
Shows the debugger with NullReferenceException when evaluating "this"
Comment 4 michael.yohe 2014-01-15 15:45:33 UTC
Created attachment 5849 [details]
Shows the actual NullReferenceException because "this" is null
Comment 5 michael.yohe 2014-01-15 15:47:13 UTC
So much for my first bug report.  Debugger was throwing an exception because "ToString()" was causing the NullReferenceException.  Not your problem.  It was mine.