This project is read-only.

ERROR: Cannot perform runtime binding on a null reference

Topics: Core, General
Jul 22, 2014 at 6:05 PM
I am using Orchard 1.8 connected to SQL Server 2012 w/ Service Pack 1. I am also using Visual Studio 2013.

I was moving right along with a new Orchard website creating an new content type called "Logo" with just the "Common Part", "Title Part" and two fields" CssClass" (text field) and "URL" (text field).

I created content type "Logo" and values entered for the "Title" = "SiteLogo", "CssClass" = A1_Logo" and the "URL" = "/OrchardLocal/".

That was successful.

I was able to create an Alternate Template "Content-Logo.Detail.cshtml" in my theme "/BootstrapThemeRed/Views/Content-Logo.Detail.cshtml" to just take the "CssClass" and "URL" field values and use them in link definition.

i.e. <a class="@Model.ContentItem.Logo.CssClass.Value" href="@Model.ContentItem.Logo.URL.Value">  </a>

The alternate template file (\Themes\BootstrapThemeRed\Views\Content-Logo.Detail.cshtml) looks like this:
@using Orchard.Utility.Extensions;


    var contentTypeClassName = ((string)Model.ContentItem.ContentType).HtmlClassify();

    var tag = Tag(Model, "article");
    var ContentItem = Model.ContentItem;
   @if (Model.Header != null){ 
    <!-- Logo Link -->
    <a class="@Model.ContentItem.Logo.CssClass.Value" href="@Model.ContentItem.Logo.URL.Value"> &nbsp;</a>


    @if (Model.Footer != null)

That also worked fine. I was able to use the view the newly formatted content which was a link the took you to the home page. The rendered HTML was <a class="A1_Logo" href="/OrchardLocal/"&nbps;</a> with following style rule applied:

/ A1 Logo in upper left corner of header/
#A1_logo, .A1_logo {
    display: block;
    width: 180px !important;
    height: 180px !important;
    background: transparent url("/OrchardLocal/Media/Default/ImageGalleries/Icons/webbuttons-and-hovers.png") no-repeat 0px 0px !important;
    margin-left: 0px;
    text-decoration: none!important;
It just styles the link with a logo background image.

The intent was to have this "Logo" Content Type display a logo in a zone using query/projections with the formatting of the template, since it is my understanding the default results of a query and projection are a list.

So, I next created a Query filtering on "Content Types" of type "Logo" saved the query; then clicked "Preview" to verify the results; which I have done before on a test site just fine.

However, I received an error message "Cannot perform runtime binding on a null reference" thrown from Line 3 In Orchard.Web\Core\Title\Views\Parts.Title_Summary.cshtml

Line 1: @{
Line 2: Orchard.ContentManagement.ContentItem contentItem = Model.ContentPart.ContentItem;
Line 3: string title = Model.Title.ToString();
Line 4: }
Line 5:

Now the site will not run at all. If I stop Visual Studio and run the site again, I still get the same core error. I can't get Orchard to even run, let alone access the admin panel to look at the query.

HELP!!! Any assistance/insight on how to recover would be much appreciated.

Thanks in advance.

Jul 22, 2014 at 6:51 PM
If is of any help in pointing me to how to fix the above issue, here is that stack trace.

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException was unhandled by user code
Message=Cannot perform runtime binding on a null reference
Source=Anonymously Hosted DynamicMethods Assembly
   at CallSite.Target(Closure , CallSite , Object )
   at ASP._Page_Core_Title_Views_Parts_Title_Summary_cshtml.Execute() in c:\Users\kengelhardt\Documents\Visual Studio 2013\Projects\A1_Website-OrchardCMS\src\Orchard.Web\Core\Title\Views\Parts.Title_Summary.cshtml:line 3
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
   at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
   at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
   at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
   at System.Web.Mvc.HtmlHelper.RenderPartialInternal(String partialViewName, ViewDataDictionary viewData, Object model, TextWriter writer, ViewEngineCollection viewEngineCollection)
   at System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData)
   at System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model)
   at Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy.ShapeTemplateBindingStrategy.Render(ShapeDescriptor shapeDescriptor, DisplayContext displayContext, HarvestShapeInfo harvestShapeInfo, HarvestShapeHit harvestShapeHit) in c:\Users\kengelhardt\Documents\Visual Studio 2013\Projects\A1_Website-OrchardCMS\src\Orchard\DisplayManagement\Descriptors\ShapeTemplateStrategy\ShapeTemplateBindingStrategy.cs:line 151
   at Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy.ShapeTemplateBindingStrategy.<>c__DisplayClass26.<>c__DisplayClass28.<Discover>b__15(DisplayContext displayContext) in c:\Users\kengelhardt\Documents\Visual Studio 2013\Projects\A1_Website-OrchardCMS\src\Orchard\DisplayManagement\Descriptors\ShapeTemplateStrategy\ShapeTemplateBindingStrategy.cs:line 133
   at Orchard.DisplayManagement.Descriptors.ShapeAlterationBuilder.<>c__DisplayClass3.<>c__DisplayClass5.<BoundAs>b__2(DisplayContext displayContext) in c:\Users\kengelhardt\Documents\Visual Studio 2013\Projects\A1_Website-OrchardCMS\src\Orchard\DisplayManagement\Descriptors\ShapeAlterationBuilder.cs:line 56
   at Orchard.DisplayManagement.Implementation.DefaultDisplayManager.Process(ShapeBinding shapeBinding, IShape shape, DisplayContext context) in c:\Users\kengelhardt\Documents\Visual Studio 2013\Projects\A1_Website-OrchardCMS\src\Orchard\DisplayManagement\Implementation\DefaultDisplayManager.cs:line 185
   at Orchard.DisplayManagement.Implementation.DefaultDisplayManager.Execute(DisplayContext context) in c:\Users\kengelhardt\Documents\Visual Studio 2013\Projects\A1_Website-OrchardCMS\src\Orchard\DisplayManagement\Implementation\DefaultDisplayManager.cs:line 94
   at Orchard.DisplayManagement.Implementation.DisplayHelper.ShapeExecute(Object shape) in c:\Users\kengelhardt\Documents\Visual Studio 2013\Projects\A1_Website-OrchardCMS\src\Orchard\DisplayManagement\Implementation\DisplayHelper.cs:line 86
   at Orchard.DisplayManagement.Implementation.DisplayHelper.Invoke(String name, INamedEnumerable`1 parameters) in c:\Users\kengelhardt\Documents\Visual Studio 2013\Projects\A1_Website-OrchardCMS\src\Orchard\DisplayManagement\Implementation\DisplayHelper.cs:line 44
   at Orchard.DisplayManagement.Implementation.DisplayHelper.TryInvoke(InvokeBinder binder, Object[] args, Object& result) in c:\Users\kengelhardt\Documents\Visual Studio 2013\Projects\A1_Website-OrchardCMS\src\Orchard\DisplayManagement\Implementation\DisplayHelper.cs:line 29
   at CallSite.Target(Closure , CallSite , Object , Object )
   at Orchard.Core.Shapes.CoreShapes.ContentZone(Object Display, Object Shape, TextWriter Output) in c:\Users\kengelhardt\Documents\Visual Studio 2013\Projects\A1_Website-OrchardCMS\src\Orchard.Web\Core\Shapes\CoreShapes.cs:line 274
Jul 22, 2014 at 7:32 PM
Bug report for this:

This exception shouldn't prevent the site from running.
Jul 22, 2014 at 7:42 PM
Thanks for the quick response.

Well for me it seems to be preventing the site from running. I can't get to anything.

So, how can I use Orchard for a corporate website that we have invested weeks learning the Orchard platform and designing around it?

Jul 22, 2014 at 7:58 PM
If you don't start the site in debug it shouldn't bother you and the site should spin up and run normally. Even if you have a debugger attached you can safely set VS to ignore this type of exception.

This is not a solution of course, just a workaround, but this shouldn't prevent you from working with Orchard.
Jul 22, 2014 at 8:11 PM
I tried doing an ctrl+ F5 "Start Without Debugging"; which yields the same "Cannot perform runtime binding on a null reference" error :-(
Jul 22, 2014 at 8:15 PM
Is there a way to restore the content in the database to the base starting point when Orchard was installed?

We just installed Orchard, selected SQL Server as the database, used the default recipe and began trying to figure out how to first make changes to the theme (which has all been checked into source control); then we went about exploring how to create a content type and change it's presentation a get it displayed in a zone as my previous post indicates.

We don't have that much entered. A few sample pages and a logo content type.
Jul 22, 2014 at 8:34 PM
Hmm, so you get a YSOD? This shouldn't happen.

You can just empty (or drop and re-create) the DB to start over, but you'll also have to clear the site settings (just remove App_Data). If you use SQL CE for development you just have to remove App_Data.
Jul 22, 2014 at 8:43 PM
Thanks. I don't know what "YSOD" means?

So your suggesting SQL Server allows one to drop and recreate the DB? If so, any idea how I explore this?

Seems like its awful technical, for anyone that want's to download Orchard and use it. Think your local "cake lady" that just want's a CMS (so content editing is easy) and stand up a site and advertise her cakes. She chose SQL server, since the Orchard videos recommend that over CE for a real website. Then the site site crashes. She's not going to have a clue of what to do.
Jul 22, 2014 at 8:48 PM
YSOD = yellow screen of death :-). The default ASP.NET error page. So my question would be, if you're not debugging, how are you actually seeing this error?

Of course resetting the site is not something the local cake lady would do. It's something actually nobody apart from developers constantly experimenting during work would do. And if Orchard crashes in a way this is necessary then it means something exceptionally bad happened, that shouldn't. I just told you how to do it because you asked.

Well, dropping and re-creating the DB is a matter of few click in SQL Server Management Studio if you have sufficient permissions, or you can explore the drop/create database commands :-).
Jul 22, 2014 at 9:04 PM
Edited Jul 22, 2014 at 9:20 PM

Just to make sure I don't hose things more than they all ready are, when you state "... clear the site settings (just remove App_Data)" are you referring to the "App_Data" folder and its contents in the "Orchard.Web" project. If so, will Orchard recreate it, when it runs again?
Jul 22, 2014 at 9:54 PM
Yes and yes.