I have an MVC view that is throwing a NullReferenceException in the following code:
<div class="center-block text-center mb15">
Showing @count of @Model.TotalItemCount results
</div>
So, I would expect that the error is that Model is null. However, the code has already made it through the following code which appears earlier in the same view:
@{
long count = Model.Count();
}
Stepping through the code shows that count is (in this case) 6, and Model.TotalItemCount is also 6, so there is no null reference.
But it's still throwing the exception!
Here's the weird bit, which makes no sense to me and is the crux of the question. When the exception is thrown I get the following in Visual Studio:
This seems to indicate that the view that is being debugged is different to the view being displayed in the editor, but
- I have deleted the
binandobjfolders and rebuilt the app, with no change, and - This view has not been changed for a couple of months and works with other controller actions (it is a
Sharedview).
Stepping through the view prior to this line in the debugger, every line is highlighted correctly (yellow bar through all text).

TotalItemCountan auto-property? Or does it have an implementation? What is the implementation ofCount? I assume it's justIEnumerable.Count()but I'd like to confirm.Modelis an instance of Troy Goode'sIPagedList<T>, and implements aCountproperty as well as inheriting fromIEnumerable<T>.