Bug 2613 - Null pointer exception in System.Data.Linq.DataContext.SetEntitySetsQueries
Summary: Null pointer exception in System.Data.Linq.DataContext.SetEntitySetsQueries
Status: RESOLVED INVALID
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Data ()
Version: unspecified
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2011-12-22 13:18 UTC by Michael Thwaite
Modified: 2012-07-03 10:27 UTC (History)
1 user (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 GitHub or Developer Community 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 Thwaite 2011-12-22 13:18:36 UTC
I have a DataClassesDataContext brought over from VS (unable to build sqldb classes but that's for another day).

The underlying data structure comprises tables joined with foreign keys:

School ->
 FoodDaysRun ->
  FoodDay ->
   Theme.

There is also the relationship of

School ->
 Theme.

So, Themes belong to schools, and FoodDays have an individual Theme.

Here is the code (an empty ASP.NET solution, marked up with the failure:


		public virtual void button1Clicked (object sender, EventArgs args)
		{
			DataClassesDataContext db=new DataClassesDataContext(); // OK
			
			School school =db.Schools.First (); // OK
			
			FoodDayRun fdr=school.FoodDayRuns.First (); // OK
			
			FoodDay fd=fdr.FoodDays.First (); // OK
			
			Theme theme=fd.Theme1; // FAIL returns: 500 error
			
//			System.NullReferenceException: Object reference not set to an instance of an object
//			  at System.Data.Linq.DataContext.SetEntitySetsQueries (System.Object entity) [0x00000] in <filename unknown>:0 
//			  at System.Data.Linq.DataContext._GetOrRegisterEntity (System.Object entity) [0x00000] in <filename unknown>:0 
//			  at System.Data.Linq.DataContext.Register (System.Object entity) [0x00000] in <filename unknown>:0 
//			  at DbLinq.Data.Linq.Sugar.Implementation.QueryRunner.Select[Theme] (DbLinq.Data.Linq.Sugar.SelectQuery selectQuery) [0x00000] in <filename unknown>:0 
//			  at DbLinq.Data.Linq.Implementation.QueryProvider`1[Theme].GetEnumerator () [0x00000] in <filename unknown>:0 
//			  at System.Data.Linq.EntityRef`1[Theme].get_Entity () [0x00000] in <filename unknown>:0 
//			  at FoodDay.get_Theme1 () [0x00000] in /Users/michael/Dropbox/Code/mono/FailDemo/FailDemo/DataClasses.designer.cs:4112 
//			  at FailDemo.Default.button1Clicked (System.Object sender, System.EventArgs args) [0x0002a] in /Users/michael/Dropbox/Code/mono/FailDemo/FailDemo/Default.aspx.cs:26 
//			  at System.Web.UI.WebControls.Button.OnClick (System.EventArgs e) [0x00000] in <filename unknown>:0 
//			  at System.Web.UI.WebControls.Button.RaisePostBackEvent (System.String eventArgument) [0x00000] in <filename unknown>:0 
//			  at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent (System.String eventArgument) [0x00000] in <filename unknown>:0 
//			  at System.Web.UI.Page.RaisePostBackEvent (IPostBackEventHandler sourceControl, System.String eventArgument) [0x00000] in <filename unknown>:0 
//			  at System.Web.UI.Page.RaisePostBackEvents () [0x00000] in <filename unknown>:0 
//			  at System.Web.UI.Page.ProcessRaiseEvents () [0x00000] in <filename unknown>:0 
//			  at System.Web.UI.Page.InternalProcessRequest () [0x00000] in <filename unknown>:0 
//			  at System.Web.UI.Page.ProcessRequest (System.Web.HttpContext context) [0x00000] in <filename unknown>:0 
			
			button1.Text = string.Format ("{0}",theme.Name);
		}
Comment 1 Michael Thwaite 2011-12-22 14:01:50 UTC
I've noticed something odd and specific to themes: the ID column (int) is the primary key but there is also a foreign key relation ship to itself. I'm going to test removing this to see the effect.

btw: this relationship works ok under VS/.net 4.0. but I'm finding that mono is far more struck about everything; I've already found and repairs dozens of wooly bits of code that VS/.NET let slide!
Comment 2 Michael Thwaite 2011-12-22 20:49:36 UTC
I've resolved the issue; there was a self-referencing fk theme.id <> theme.id which is stupid to be honest but .NET was ok with it!

Should this be tracked or a better error handler added?
Comment 3 Michael Thwaite 2012-07-03 10:27:56 UTC
Caused by bad db foreign key relationship.