I have an ASPNET MVC application that works fine locally but when I deployed it to production I get the following stack trace.
There are a few puzzling things about this stack trace, for one everything worked fine before i deployed my changes, for two the location of the code is wrong it's now on a production server not my dev machine and for three Rework is a controller method, not an object
2/28/2011 11:03:47 PM COB_Database.Controllers.ClaimsController Rework Object reference
not set to an instance of an object. at COB_Database.ViewModels.ErrorVM.
<>c__DisplayClass12.<.ctor>b__1(Error err) in
C:\Users\jperrine251\documents\visual studio 2010\Projects\COB Database\COB
Database\ViewModels\ErrorVM.cs:line 26 at
System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext() at
System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) at
System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at
COB_Database.ViewModels.ErrorVM..ctor(User user, Claim claim, IEnumerable`1 actions,
IEnumerable`1 users, IEnumerable`1 referralReasons, Boolean editing) in
C:\Users\jperrine251\documents\visual studio 2010\Projects\COB Database\COB
Database\ViewModels\ErrorVM.cs:line 26 at
COB_Database.Controllers.ClaimsController.Rework(Int32 id) in
C:\Users\jperrine251\documents\visual studio 2010\Projects\COB Database\COB
Database\Controllers\ClaimsController.cs:line 160 at lambda_method(Closure ,
ControllerBase , Object[] ) at
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[]
parameters) at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext
controllerContext, IDictionary`2 parameters) at
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext
controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) at
System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.
<InvokeActionMethodWithFilters>b__12() at
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter,
ActionExecutingContext preContext, Func`1 continuation) at
System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<>c__DisplayClass17.
<InvokeActionMethodWithFilters>b__14() at
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext
controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2
parameters) at
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext
controllerContext, String actionName)
Anyone have any ideas?
EDIT: The line in question in the stack trace is this
UsersErrors = claim.Errors.Where(err => err.UserID == user.id && err.ErrorActionID != null &&
err.ErrorActionLogs.OrderByDescending(eal => eal.id).FirstOrDefault().Timestamp >= DateTime.Now.AddHours(-10)).ToList();
And UsersErrors is defined as List<Error> UsersErrors
I tried changing the code to this but still no luck:
var userErrors = claim.Errors.Where(err => err.UserID == user.id && err.ErrorActionID != null &&
err.ErrorActionLogs.OrderByDescending(eal => eal.id).FirstOrDefault().Timestamp >= DateTime.Now.AddHours(-10));
UsersErrors = userErrors == null ? new List<Error>() : userErrors.ToList();
Edit, I've isolated the line causing the problem further, I took the above code and broke it down into predicates and passed those to my linq expression, the following is what is failing (but working locally)
Func<Error, bool> errorLogp =
(err) =>
err.ErrorActionLogs
.OrderByDescending(eal => eal.id)
.FirstOrDefault().Timestamp >= DateTime.Now.AddHours(-10);
Errors have a log of actions taken on them, this is just grabbing the most recent and ensuring it was done in the last 10 hours, I've checked the database for the record i'm testing on and it is present along with an error action log that meets the requirements
EDIT: Also to ensure that claim.Errors isn't null I've done the following
UsersErrors = Claim.Errors == null ?
new List<Error>() :
Claim.Errors.Where(err => errorp(err) && errorLogp(err)).ToList();
but the code still bombs out at the errorLogp predicate Func