This project is read-only.


Object reference not set to an instance of an object


ASP.NET MVC Object params
[DonutOutputCache(Duration = 252000, VaryByParam = "*")]
public ActionResult Index(RepositoryParams Params)

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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

Source Error:

Line 46: public string BuildKeyFragment(KeyValuePair<string, object> routeValue)
Line 47: {
Line 48: return string.Format("{0}={1}#", routeValue.Key.ToLowerInvariant(), routeValue.Value.ToString().ToLowerInvariant());
Line 49: }
Line 50: }

Source File: DevTrends.MvcDonutCaching\DevTrends.MvcDonutCaching\KeyBuilder.cs Line: 48
Closed Sep 11, 2013 at 6:18 PM by moonpyk
Fixed by commit ecd316c0860ee07000dd68c4873929f323e46f51.

Well be available with next release.


DevTrends wrote Mar 23, 2012 at 10:34 AM

I am going to need some more information. What is the structure of RepositoryParams class and what are the values when the exception is raised? Also, are you doing a get or post?

vtelushkin wrote Mar 28, 2012 at 1:39 PM

public class RepositoryParams
public string catalog { get; set; }
public string category { get; set; }
public string goodtype { get; set; }
public string st { get; set; }

public string f_size { get; set; }
public string f_subcat { get; set; }
public int? f_price_min { get; set; }
public int? f_price_max { get; set; }
public int? pge { get; set; }
public int? pgeS { get; set; }
public string f_density { get; set; }
public string f_brand { get; set; }
public string f_state { get; set; }
public string sort { get; set; }        

public bool NeedFilter { get; set; }
public Guid SessionID { get; set; }

public string closed_filters { get; set; }

Almost every property of this class can be null

The problem is that the parameter of the function BuildKeyFragment in KeyBuilder.cs
KeyValuePair routeValue
Value may be null and can`t execute .ToString() method

In order not to spend too much time on the analysis of errors, I replaced the line
return string.Format("{0}={1}#", routeValue.Key.ToLowerInvariant(), routeValue.Value.ToString().ToLowerInvariant());

for this variant
var val = ((routeValue.Value != null) ? routeValue.Value.ToString().ToLowerInvariant() : "null");
return string.Format("{0}={1}#", routeValue.Key.ToLowerInvariant(), val);

SachinItcube wrote May 9, 2012 at 2:28 PM

I also got the same issue.
In my case if we keep the page for 1 hr idle and after that I tried to do some operation. In web.config file the session timeout is 30min.

How to handle this? Please let me know.


ronaldsteen wrote May 21, 2012 at 8:15 PM

I'm having the same issue with parameters that have value null.

I am trying to use Donut Caching to put user specific content in cached Umbraco content pages.
I've replaced the OutputCache attribute in the Umbraco sources with the DonutOutputCache. I suspect Umbraco of putting in empty parameters.

[NullReferenceException: Object reference not set to an instance of an object.]
DevTrends.MvcDonutCaching.KeyBuilder.BuildKeyFragment(KeyValuePair2 routeValue) +53
DevTrends.MvcDonutCaching.KeyBuilder.BuildKey(String controllerName, String actionName, RouteValueDictionary routeValues) +485
DevTrends.MvcDonutCaching.KeyGenerator.GenerateKey(ControllerContext context, CacheSettings cacheSettings) +1728
DevTrends.MvcDonutCaching.DonutOutputCacheAttribute.ExecuteCallback(ControllerContext context, Boolean hasErrors) +43
System.Web.Mvc.ControllerActionInvoker.InvokeExceptionFilters(ControllerContext controllerContext, IList
1 filters, Exception exception) +169
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +825561
System.Web.Mvc.Controller.ExecuteCore() +158
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +334
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +61
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +19
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +53
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +468
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +374

ronaldsteen wrote May 21, 2012 at 8:22 PM

I see that blanciq already fixed it and put in a pull request.. Please fix this and put a new release in NuGet so everybody can use this great package to it's full potential :)