Null Reference Exception trying to add new Custom Form

Topics: General, Troubleshooting
Sep 23, 2012 at 7:00 PM

I filed this as an issue, but I thought it might elicit some thoughts in discussion.

In Orchard 1.51, I'm trying to add a new custom form from the "Manage Custom Forms" interface (with no forms currently existing). I'm getting a null reference exception. This is similar to an error that Cowboy Hell had last month at StackOverflow: Orchard Create Featured Items Error. He followed up and closed the question by stating: "problem was in the DB. After I removed it and deployed once again it works."

I'm not surprised to hear this, but I have a site with lots of content and configuration. I have not been using migrations to version the DB. The site started on an earler version of Orchard and has been successfully brought forward.

I've been trying to add "Custom Forms". Disabling and re-enabling the Custom Forms module does not work. I don't seen any clean way to completly remove it from the project and re-add it. I could delete that module from the file system and delete the one DB table that specifically references custom forms Orchard_CustomForms_CustomFormPartRecord but that makes me nervous.

    Object reference not set to an instance of an object. 
   
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

   
Source Error: 


   
Line 1:  @{
   
Line 2:      var typeDisplayName = Model.ContentItem.TypeDefinition.DisplayName;
   
Line 3:      var pageTitle = T("New {0}", typeDisplayName);
   
Line 4:  
   
Line 5:      Layout.Title = (string)pageTitle.Text;


   
Source File: dev\Core\Contents\Views\Admin\Create.cshtml    Line: 3 

   
Stack Trace: 

   
[NullReferenceException: Object reference not set to an instance of an object.]
   
Orchard.Localization.Text.Get(String textHint, Object[] args) in    
   
\dev\src\Orchard\Localization\Text.cs:31
   
CallSite.Target(Closure , CallSite , Localizer , String , Object ) +169
    ASP
._Page_Core_Contents_Views_admin_Create_cshtml.Execute() in \dev\Core\Contents\Views\Admin\Create.cshtml:3
   
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +279
   
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +103
   
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +172
   
Orchard.Mvc.ViewEngines.ThemeAwareness.<>c__DisplayClass7.<FindView>b__5(ViewContext  viewContext, TextWriter writer, IViewDataContainer viewDataContainer) in \dev\src\Orchard\Mvc\ViewEngines\ThemeAwareness\LayoutAwareViewEngine.cs:59
  
Orchard.Mvc.ViewEngines.ThemeAwareness.LayoutView.Render(ViewContext viewContext, TextWriter writer) in \dev\src\Orchard\Mvc\ViewEngines\ThemeAwareness\LayoutAwareViewEngine.cs:90
  
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +383
  
System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +32
  
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter,      ResultExecutingContext preContext, Func`1 continuation) +825572

   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`
1 filters, ActionResult actionResult) +265
  
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +825600
  
System.Web.Mvc.Controller.ExecuteCore() +159
  
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +335
  
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +62
  
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +20
  
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +54
  
Orchard.Mvc.Routes.HttpAsyncHandler.EndProcessRequest(IAsyncResult result) in \dev\src\Orchard\Mvc\Routes\ShellRoute.cs:147
  
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +469
  
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +375

Coordinator
Sep 23, 2012 at 7:10 PM

From the stack trace, it looks like you have some corrupted data: there seems to be a content type with a null display name.