THESE FORUMS ARE NOW FROZEN
Please choose "Forums" from the Main menu of www.entityspaces.net to get to our new forums.

NullReferenceException in EntitySpaces_C#_ASPX.csgen template when loading foreign keys.

rated by 0 users
This post has 2 Replies | 2 Followers

Top 50 Contributor
Posts 41
mfreidge Posted: 10-10-2007 5:52 AM

My MyGeneration  project for ASP.NET template had invalid(I've created a copy of  template instance) foreign key names for the table and it caused

**ERROR*** [NullReferenceException] Object reference not set to an instance of an object.
Canceled Template execution: EntitySpaces C# ASPX Page.
 
I would prefer to see mote detailed(with full call stack) message from MyGeneration.

To improve error handling it is required to add "not null check" in a few places in the code of EntitySpaces_C#_ASPX.csgen /EntitySpaces_C#_ASCX.csgen like the following(my changes are in bold)
// Lookups section
                              IForeignKey fk = table.ForeignKeys[fkName];    
                              if(fk!=null) //mnf
                              {//mnf
                                    Dnp.Utils.TableRelation tr = new Dnp.Utils.TableRelation(table, fk);
                        %>
            this.vlnk<%=esPlugIn.PropertyName(col)%>.Text = <%=tr.LookupName%>(entity.<%=esPlugIn.PropertyName(tr.PrimaryColumns[0])%>);
            this.vlnk<%=esPlugIn.PropertyName(col)%>.NavigateUrl = Globals.ApplicationPath + "/tabid/" + TabId + "/pagename/<%=esPlugIn.Entity(tr.ForeignTable)%>/<%=esPlugIn.PropertyName(tr.ForeignColumns[0])%>/" + entity.str.<%=esPlugIn.PropertyName(tr.PrimaryColumns[0])%> + "/default.aspx";<%
                              }//mnf
 
I understand, that in ES2008 the template suite will be completely different, but this post could help someone in the meantime.
Michael Freidgeim Blog: http://geekswithblogs.net/mnf/
Top 10 Contributor
Posts 905
We can certainly put the check in, but can you expand on how you get an invalid FK name? If the FK is not there it shouldn't even show up in the UI as an option for lookup use. Did you have a stale recorded project or something?

Regards, Scott Schecter EntitySpaces | Blog | Twitter

Top 50 Contributor
Posts 41

Hi Scott,

In MyGeneration Project I created an ASPX.csgen template instance for a table and selected all appropriate fields.
Then within project tree I made a copy of instance(which caused the problem), opened instance and recorded details for another database table.
I beleive that similar issue would happen, if after template instance in the project was created , someone will rename/drop table relationship in the database. 

Michael Freidgeim Blog: http://geekswithblogs.net/mnf/
Page 1 of 1 (3 items) | RSS
Copyright © 2005 - 2009, EntitySpaces, LLC