CodeSmith Community
Your Code. Your Way. Faster!

System.NullReferenceException on create an Instance of CodeTemplate

Latest post 10-22-2008 5:21 PM by blake05. 5 replies.
  • 11-28-2005 2:41 PM

    System.NullReferenceException on create an Instance of CodeTemplate

    Hi Guys,
     
    I tryed (i'm still trying) to write a simple Template - Generator in C# using VS2005 and CodeSmith.Engine.
    When i tryed to instantiate an Object from CodeTemplate Class like:
     
    ..
    ..
    using CodeSmith.Engine; 
     
    .
    .
    .
    CodeTemplate ctem = new CodeTemplate();
     
    I got SystemNullReferenceException.
     
    I use CodeSmith 3.1
     
    Any ideas?
     
    thanks
     
    Paul.
      
    • Post Points: 35
  • 02-08-2008 11:36 AM In reply to

    Re: System.NullReferenceException on create an Instance of CodeTemplate

    Hi,

     I'm having the same problem as I'm trying to render a template from a template, but I cannot create an instance.

    Also, I cannot see child template properties in the property grid of the master template: those properties are defined in the code-behind class of the child template.

    Has anyone a solution about that?

    • Post Points: 5
  • 02-19-2008 8:36 AM In reply to

    Re: System.NullReferenceException on create an Instance of CodeTemplate

    Hi, any news about this topic?
    • Post Points: 35
  • 09-16-2008 8:18 AM In reply to

    • blake05
    • Top 10 Contributor
    • Joined on 04-03-2008
    • Wisconsin
    • Posts 524
    • Points 9,755

    Re: System.NullReferenceException on create an Instance of CodeTemplate

    Hello,

    I have filed this as a critical bug, I will update this thread when a solution is available.

    Thank you,
    Blake Niemyjski

    Blake Niemyjski

    CodeSmith Tools, LLC. Software Development Engineer

    Blog: http://windowscoding.com/blogs/blake/

    ----------------------------------------------------------------------
     Member of the .NetTiers team | Visit http://www.nettiers.com
    ----------------------------------------------------------------------

    • Post Points: 35
  • 10-22-2008 4:31 PM In reply to

    • Alverant
    • Not Ranked
    • Joined on 10-20-2008
    • Posts 6
    • Points 180

    Re: System.NullReferenceException on create an Instance of CodeTemplate

    Is there any progress? We're converting our CodeSmith cst files from v2 to v5. For the most part it works but a key file has this error:

    System.NullReferenceException: Object reference not set to an instance of an object.
       at CodeSmith.Engine.CodeTemplate..ctor()
       at _CodeSmith.GenerateCode_cst.GetTemplate(String templateType) in c:\CodeGenOrig\CodeGen\GenerateCode.cst:line 65
       at _CodeSmith.GenerateCode_cst.Go() in c:\CodeGenOrig\CodeGen\GenerateCode.cst:line 191
       at _CodeSmith.GenerateCode_cst.__RenderMethod1(TextWriter writer, Control control) in c:\CodeGenOrig\CodeGen\GenerateCode.cst:line 291
       at CodeSmith.Engine.DelegateControl.Render(TextWriter writer)
       at CodeSmith.Engine.Control.RenderChildren(TextWriter writer)
       at CodeSmith.Engine.Control.Render(TextWriter writer)
       at CodeSmith.Engine.CodeTemplate.Render(TextWriter writer)
       at CodeSmith.Engine.CodeTemplate.RenderToString()
       at CodeSmith.Gui.CodeTemplateGenerator.f(Object A_0, EventArgs A_1)

    Line 65 is:
    CodeTemplate currentTemplate = new CodeTemplate();

    What we want to do is create an empty template then assign a particular template to that variable in a switch statement.
    (example) currentTemplate = this.CompileTemplate(this.CodeTemplateInfo.DirectoryName + "_DataAccessLayer.cst");

    • Post Points: 35
  • 10-22-2008 5:21 PM In reply to

    • blake05
    • Top 10 Contributor
    • Joined on 04-03-2008
    • Wisconsin
    • Posts 524
    • Points 9,755

    Re: System.NullReferenceException on create an Instance of CodeTemplate

    Hello,

    You can't inheirit from CodeTemplate. To do what your doing requires that you create a new template. Please check into Master and Sub templates.

    Thanks
    -Blake Niemyjski

    Blake Niemyjski

    CodeSmith Tools, LLC. Software Development Engineer

    Blog: http://windowscoding.com/blogs/blake/

    ----------------------------------------------------------------------
     Member of the .NetTiers team | Visit http://www.nettiers.com
    ----------------------------------------------------------------------

    • Post Points: 5
Page 1 of 1 (6 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems