7

We are trying to upgrade an existing .NET DD4T 1.31 website to .NET DD4T2.0. We have made necessary changes to compile the Website with latest DD4T 2.0 DLL successfully.

Now I would like to test whether DD4T 2.0 is backward compatible with the previous version DD4T 1.31 - So have not done anything on the CM side apart from installing the latest TBBs (no publish with latest TBBs).

Q: Assuming DD4T 2.0 is backward compatible on CD side, if I am running the website with DD4T 2.0 then calling the @Html.RenderComponentPresentationsByView("viewname") is giving me below error:

Object reference not set to an instance of an object.

The stack Trace and Event Log error is as below:

[NullReferenceException: Object reference not set to an instance of an object.]
   DD4T.Mvc.Html.TridionHelper.RenderComponentPresentations(HtmlHelper helper, String[] byComponentTemplate, String bySchema, IComponentPresentationRenderer renderer) in C:\projects\dd4t-mvc\source\dd4t.mvc\html\TridionHelper.cs:88
   .....Campaign_cshtml.Execute() in c:\DD4TUpgrade\CodeBase-TFS\International\Platform\(trimmed)
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +252
   System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +147
   System.Web.WebPages.StartPage.ExecutePageHierarchy() +88
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +106
   System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +374
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +89
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +833
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +833
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +81
   System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +186
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +38
   System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +65
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +38
   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +44
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +65
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +38
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +399
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Any help would be appreciated; it might be something minor I am missing.

3

You seem to be having a dependency injection issue, my friend :)

Line 88 in TridionHelper.cs is:

_logger.Information(">>RenderComponentPresentations", LoggingCategory.Performance);

_logger seems to null, hence the NullReferenceException.

_logger is initialized at line 35 in the static constructor and takes value of logger:

var logger = DependencyResolver.Current.GetService<ILogger>();
  • thanks Mihai...indeed it was the dependency issue but not only the logger one but other 3 as well, as mentioned in my answer – Pankaj Gaur Apr 5 '16 at 10:57
2

This indeed requires following four dependencies to be added (Thanks Siawash):

var config = DependencyResolver.Current.GetService<IDD4TConfiguration>();
var logger = DependencyResolver.Current.GetService<ILogger>();
var renderer = DependencyResolver.Current.GetService<IComponentPresentationRenderer>();
var linkResolver = DependencyResolver.Current.GetService<ILinkResolver>();

These four were coming as null due to some castle windsor (DI I am using) logic we had.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.