0

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

4
  • 1
    It looks like you have an enumerable collection (List<T>?) that is calling .Where(...), but the collection is null. Most likely in the Rework method call. Check it for any thing like that, and trace it back to where it should be populated. From there you should have a better picture of whats happening. Are your connection strings correct? Commented Mar 1, 2011 at 14:01
  • Yeah I have a list that is being populated, it works fine on development but on production bombs out, there's nothing wrong in the code and the connection to the db is working fine, it's baffling Commented Mar 1, 2011 at 15:24
  • 1
    Are you absolutly sure it's being populated? Put a null check and write the result to ViewData[] and then to the screen to verify it. Commented Mar 1, 2011 at 15:30
  • See some of my edits for more information Commented Mar 1, 2011 at 16:16

4 Answers 4

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I am, see updates for errorVM code for the line that bombs out, I've added a null check for the only dependent object on that line user and it still bombs
Nope, everything is in the database and this segment of code allows the editing of previously worked objects, I had worked this object this morning and this is the same view model that loads the editing and when first working an object
As I was typing this out I saw that you found your issue. My next step was SQL profiler ;)
1

A few things to consider:

  1. 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.)
  2. 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.

Comments

0

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 (?)

Comments

0

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

1 Comment

Nevertheless, be sure to read - and understand - all the comments and answers you've been given so far. They contain absolutely crucial information lest you want this to happen again. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.