Bug 1566 - Debugger crashes out with Unhandled Exception when null reference in Object Initializer
Summary: Debugger crashes out with Unhandled Exception when null reference in Object I...
Status: RESOLVED FIXED
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: Debugger ()
Version: 2.8
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Jeffrey Stedfast
URL:
Depends on:
Blocks:
 
Reported: 2011-10-19 07:14 UTC by Dermot
Modified: 2012-05-14 14:53 UTC (History)
3 users (show)

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

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 FIXED

Description Dermot 2011-10-19 07:14:24 UTC
When using object initializer syntax, if value within the initializer is null, monodevelop crashes with an unhandled monodevelop exception


eg:


TestClass myObject = new TestClass()
{
    Prop1 = Something.Value
};

Where Something is null.
Comment 1 Miguel de Icaza [MSFT] 2011-11-14 16:14:14 UTC
Without a complete sample, it is not possible to reproduce this.

This is what I tried, and it works.

Perhaps some steps to reproduce would be useful
using System.Collections.Generic;
using System.Globalization;
using System;

class A
{
	public  string Value;
	
    public static void Main ()
    {
		
		var Something = new  A ();
	TestClass myObject = new TestClass()
	{
			
    	Prop1 = Something.Value
	};
    }
}

public class TestClass {
	public string Prop1;
}
Comment 2 Alan McGovern 2011-11-15 14:41:00 UTC
What exactly is it that crashes? Are you saying the IDE itself crashes when you execute your application under the debugger?
Comment 3 Dermot 2012-05-13 20:45:32 UTC
From what I remember (its been months since i've seen this), the IDE itself crashes. Looking at Miguels sample, I dont think that would cause it to crash. The problem would occur of var Something was null.

eg (modified version of Miguel's sample):

using System.Collections.Generic;
using System.Globalization;
using System;

class A
{
    public  string Value;

    public static void Main ()
    {
         //Note I am changing this so that Something is not initialized.
        TestSomething  Something;    // = new  A ();
    TestClass myObject = new TestClass()
    {

        Prop1 = Something.Value
    };
    }
}

public class TestClass {
    public string Prop1;
}

public class TestSomething {
    public string Property1 {get;set;}
}


Obviously the above code is incorrect and a null reference exception will occur at runtime. The issue I was reporting was that when debugging and coming across this bug, rather than an exception being thrown, the entire IDE would crash. I have not come across it in a while, so if the above modified sample doesnt cause it, I guess it can be considered fixed.
Comment 4 Jeffrey Stedfast 2012-05-14 14:53:10 UTC
MonoDevelop no longer crashes, at least not with 3.0.1

We just throw up a dialog with the app's exception info.