The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

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

Last post 10-12-2007, 8:30 PM by mfreidge. 2 replies.
Sort Posts: Previous Next
  •  10-10-2007, 5:52 AM 5745

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

    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/
  •  10-10-2007, 2:49 PM 5773 in reply to 5745

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

    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 | My Site
  •  10-12-2007, 8:30 PM 5835 in reply to 5773

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

    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/
View as RSS news feed in XML