Geeks With Blogs

News My Blog has been MOVED to
Michael Freidgeim's OLD Blog My Blog has been MOVED to
I am using MyGeneration Project  to generate admin web pages using EntitySpaces Templates for ASP.NET  . Filling templates is  very time consuming, and I decided to copy  template instance for one table as a start point for other table. It didn't save much , because it require you to do everything differently for each table anyway. And it also causes an errors.
I've done selections im multiple tabs, but when I Executed template instances, I've got errors
**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.
 Fortunately, templates are relatively  easy to Debug  , and I found that when I've copied template instance, foreign keys from one table were copied to another, even if they are not applicable.
Debugger showed  lookupColumns={|CountryCode|FK_tblCarHireCompanyCountries_tblRefCountryName|CountryName^|HireCompanyCode|FK_tblCarHireCompanyCountries_tblRefCarHireCompanies|ShortName}

During execution code reads the foreign key name for a table and tryes to foreign key. If the name is wrong, it returns null, which causes the NullReferenceException in the call to
 Dnp.Utils.TableRelation(table, fk);
It is relatively easy to fix code by adding not null check.but there are a few places in the code where it should be done.
For example see my changes  in bold:
 // Lookups section
                              IForeignKey fk = table.ForeignKeys[fkName];    
                              if(fk!=null) //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";<%
  Mike.Griffin promises  that the ASP.NET templates will be completely fixed in EntitySpaces 2008.
Posted on Monday, October 8, 2007 7:35 PM ASP.NET , Code Generation | Back to top

Comments on this post: NullReferenceException in EntitySpaces_C#_ASPX.csgen template after copy template instance

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Michael Freidgeim | Powered by: