U4-2324 - Custom routing and UmbracoHelper.Field(...) null reference exception

Created by Pintér Ákos 05 Jun 2013, 01:11:27 Updated by Shannon Deminick 20 Jun 2013, 01:26:57

This is the scenario:

  • I register a full custom route that is bound to a SurfaceControllers action method
  • In the action method I query the root element of my contents and create a RenderModel instance from it then I return with corresponding view with the model: var root = Umbraco.TypedContentAtRoot().First(); var model = new RenderModel(root, new System.Globalization.CultureInfo("hu-HU")); return View(model);
  • My view contains UmbracoHelper.Field calls, but it throws NullReferenceException. Here is the problematic code (from Umbraco source): //this is here to figure out if this request is in the context of a partial if (_umbracoContext.PublishedContentRequest.PublishedContent.Id != currentPage.Id) item.NodeId = currentPage.Id.ToString(); _umbracoContext.PublishedContentRequest is not assigned because of the custom routing.

I think in this scenario it is expected to use UmbracoHelper.Field(...) (and all other helper methods) without problems because the View has valid Umbraco RenderModel.


Shannon Deminick 20 Jun 2013, 01:26:54

Fixed in rev 2161ec98b0fcb408aa9e24b0ef7a9ecbc67538c5

Priority: Normal

Type: Bug

State: Fixed

Assignee: Shannon Deminick

Difficulty: Normal


Backwards Compatible: True

Fix Submitted:

Affected versions: 6.1.0, 6.1.1, 6.0.5

Due in version: 6.0.7


Story Points: