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 userError开发者_高级运维s = 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
Are you jperrine251? If that's not you, your code isn't running on the server. From what I can tell it looks like your error handling code is making some assumptions that don't hold in production and the whole thing is bombing out. Be very defensive in your error handling.
Posting applicable code from ErrorVM and ClaimsController would be helpful too.
A few things to consider:
- The location of the code is from the PDB (symbol) files that you compiled on your machine. It doesn't update when you deploy to a different environment. The location does give you an exact line number to investigate though, which is good. (For future production releases, you will want to compile your code in release mode and not debug mode.)
- The exception message is "Object reference not set to an instance of an object." This exception isn't telling you that Rework is an object, but that during the rework action a NullReferenceException was thrown. Somewhere on line 26 of ErrorVM.cs you have a variable that is null and you're trying to access one of its members.
The location is where the code was compiled and therefore it's normal that it has your development path (not the production box since the source code was never on that box)
As far as the error it looks like you have a null reference inside the ErrorVM
ViewModels\ErrorVM.cs:line 26 at
It might be that the original error is being composed during the process of displaying the error view (?)
I found the problem, looks like there was some data missing from the database that was expected to be there, thanks for all the help everyone
精彩评论