U4-7950 - NullReferenceException when performing any AJAX call in 7.4.0.

Created by Marc van de Wert 12 Feb 2016, 08:49:07 Updated by Shannon Deminick 16 Feb 2016, 10:13:16

Relates to: U4-8000

Relates to: U4-7754

Straight after upgrading to Umbraco 7.4.0, when I perform an AJAX call (any call, every call, on different pages), the page does not get updated.

I expected my partial view to get updated, but that was not happening. I placed a breakpoint in my SurfaceController and the breakpoint got hit. After I return the partial view, with model I get a NullReferenceException.

[HttpPost] [ValidateAntiForgeryToken] public ActionResult ChangeItemQuantity(ItemQuantityModel model) { // Do stuff.

        ShoppingCartModel shoppingCartModel = new ShoppingCartModel();
        return PartialView("ShoppingCart", shoppingCartModel); // Update the entire shopping cart because products can be removed.
    }

System.NullReferenceException: Object reference not set to an instance of an object. at Umbraco.Web.Mvc.UmbracoViewPage1.SetViewData(ViewDataDictionary viewData) at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) at Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer) at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList1 filters, ActionResult actionResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.b__1e(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) at System.Web.Mvc.Controller.b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) at System.Web.Mvc.MvcHandler.b__5(IAsyncResult asyncResult, ProcessRequestState innerState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

2 Attachments

Download UmbracoTraceLog.PDC-DEV08.txt

Download umbraco.zip

Comments

Sebastiaan Janssen 12 Feb 2016, 13:51:00

Same error here: https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/75027-umbraco-74-error-loading-partial-view-script-file-viewsmacropartialspageheadercshtml

Wondering if you missed something during upgrading because while I have never done AJAX calls like this, I certainly have upgraded sites with partial view macros from 7.2/7.3 to 7.4 and that works fine for me.


Marc van de Wert 12 Feb 2016, 15:39:56

@sebastiaan I've send you two projects, both fresh installs from NuGet via WeTransfer. One is 7.3.7 and one is 7.4.0. 7.3.7 is working and 7.4.0 is not.


Sebastiaan Janssen 12 Feb 2016, 15:49:40

Thanks, also got one from Mohamed in the Our thread.. will have a look Monday.


Sebastiaan Janssen 15 Feb 2016, 07:18:54

Okay, found the cause on this line: https://github.com/umbraco/Umbraco-CMS/blob/a1b98b6e316323a2f25ace1bb94e78e1c8d296ee/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs#L151

The UmbracoContext.PublishedContentRequest is null because we are not doing a PublishedContentRequest in ajax call. We should just have a default culture before we try to ask for this one.


Stephan 15 Feb 2016, 07:29:47

Will fix.


Sebastiaan Janssen 15 Feb 2016, 07:30:37

PR here: https://github.com/umbraco/Umbraco-CMS/pull/1118


Stephan 15 Feb 2016, 07:30:59

Will review then ;-)


Sebastiaan Janssen 15 Feb 2016, 07:42:22

The attached umbraco.dll includes the fix from the PR above. I'll investigate a way to inject the culture as well but this should alleviate the problem for now.


Sebastiaan Janssen 15 Feb 2016, 07:54:51

Looks like the safest way to set the culture is to let people just set CultureInfo.CurrentCulture before rendering a view, so I'll leave the fix as it is now.


Stephan 15 Feb 2016, 14:21:09

merged


Priority: Major

Type: Bug

State: Fixed

Assignee:

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions: 7.4.0

Due in version: 7.4.1

Sprint: Sprint 9

Story Points:

Cycle: