Object reference not set to an instance of an object - Happens after cache reset
Hey,
I'm getting this error on my site:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Line 38: else
Line 39: {
Line 40: @Html.Action("GetTTForm", "Membership", new { currentNodeId = Model.Id, currentUrl = library.NiceUrl(Model.Id), formAction = Model.FormAction })
Line 41: }
On the member login page of the site, but it only seems to appear after the macro cache time is up which is currently an hour. If I delete my AppData folder and swap it with another version of my AppData folder and then republish the entire site - the problem page will work again for the next hour.
I'm no where near an expert in umbraco, but I am finding this a very vague error - the controller it is referencing hasn't changed (to be clear this page on the site worked up with no problems until recently) and none of the ID's / Variables it operates have also changed.
Is it at all possible it could be an IIS issue causing a crash when the cache is renewed?
Any help would be fantastic as this has plagued me for all this week!
Is there a stack trace to go along with the error message? There usually is in the Umbraco log file. Also, which version of Umbraco are you using?
You might try splitting that line into a few different lines to help narrow down the issue. For example, perhaps Model is null sometimes for some reason. If you put the error on a different line (var modelId = Model.Id;), then you might get some info about the particular member access attempt that is causing the error.
You could also try logging some variables to see if that helps narrow down the issue. That works like this: LogHelper.Info<SomeClass>("Some message.");
Try removing that try/catch block. It seems to be preventing the stack trace from showing the true source of the exception.
Alternatively, if you use LogHelper.Error<MembershipController>("Error getting My TT form", ex);, that should show the true stack trace to help you narrow down the error.
If you break that into multiple lines, you should be able to figure out exactly which part is causing an issue. For example, you can create a variable like this:
var loginPageUrl = string.Format("{0}?{1}={2}", currentUrl, domain.Constants.QueryString.ACTION, Enums.EnMyTTAction.Login);
Then when constructing your MemberShipViewModel, you can assign the property to the variable value: LoginPageUrl = loginPageUrl.
Next time you get an error, you'll have a better idea of what exactly is causing it.
Alternatively, you can debug it locally by setting a breakpoint to see what's null. You can break on the error, the change the stack trace and inspect the variables. You can reduce the macro cache period so the error happens more frequently (rather than after an hour).
Thank you Nicolas so much for your help, I've managed to sort the issue. By splitting the line up like this:
var myTTPage = new CacheController().GetCachedMyTTPage(currentNodeId);
var model = new MembershipViewModel();
var loginPageUrl = string.Format("{0}?{1}={2}", currentUrl, domain.Constants.QueryString.ACTION, Enums.EnMyTTAction.Login);
var RegisterPageUrl = string.Format("{0}?{1}={2}", currentUrl, domain.Constants.QueryString.ACTION, Enums.EnMyTTAction.Register);
var ForgottenPasswordPageUrl = string.Format("{0}?{1}={2}", currentUrl, domain.Constants.QueryString.ACTION, Enums.EnMyTTAction.ForgottenPassword);
var VisitorType = Session.GetVisitor().VisitorType;
var LoginIntroductoryText = myTTPage.MyTTPageLoginIntroductoryText;
var RegisterIntroductoryText = myTTPage.MyTTPageRegisterIntroductoryText;
var ImageUrl = myTTPage.MyTTPageMainImage.Url;
I managed to pin point the issue to the last line:
var ImageUrl = myTTPage.MyTTPageMainImage.Url;
There wasn't an image selected in the back office causing the issue!
Object reference not set to an instance of an object - Happens after cache reset
Hey,
I'm getting this error on my site:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
On the member login page of the site, but it only seems to appear after the macro cache time is up which is currently an hour. If I delete my AppData folder and swap it with another version of my AppData folder and then republish the entire site - the problem page will work again for the next hour.
I'm no where near an expert in umbraco, but I am finding this a very vague error - the controller it is referencing hasn't changed (to be clear this page on the site worked up with no problems until recently) and none of the ID's / Variables it operates have also changed.
Is it at all possible it could be an IIS issue causing a crash when the cache is renewed?
Any help would be fantastic as this has plagued me for all this week!
Thanks,
Is there a stack trace to go along with the error message? There usually is in the Umbraco log file. Also, which version of Umbraco are you using?
You might try splitting that line into a few different lines to help narrow down the issue. For example, perhaps
Model
is null sometimes for some reason. If you put the error on a different line (var modelId = Model.Id;
), then you might get some info about the particular member access attempt that is causing the error.You could also try logging some variables to see if that helps narrow down the issue. That works like this:
LogHelper.Info<SomeClass>("Some message.");
Thanks Nicholas,
here is the stack trace to go with it:
I'll take a look at your other suggestions in the mean time,
Thanks.
What does line 324 of
MemberShipController
look like?:Based on this part of the stack trace, that's where the error is.
Try removing that try/catch block. It seems to be preventing the stack trace from showing the true source of the exception.
Alternatively, if you use
LogHelper.Error<MembershipController>("Error getting My TT form", ex);
, that should show the true stack trace to help you narrow down the error.Ok, I removed the catch and getting the same error - but the stack trace now looks like this:
Line 272 is refering to this:
Sounds like the error is somewhere in here (since this is all one line of code):
If you break that into multiple lines, you should be able to figure out exactly which part is causing an issue. For example, you can create a variable like this:
Then when constructing your
MemberShipViewModel
, you can assign the property to the variable value:LoginPageUrl = loginPageUrl
.Next time you get an error, you'll have a better idea of what exactly is causing it.
Alternatively, you can debug it locally by setting a breakpoint to see what's null. You can break on the error, the change the stack trace and inspect the variables. You can reduce the macro cache period so the error happens more frequently (rather than after an hour).
Thank you Nicolas so much for your help, I've managed to sort the issue. By splitting the line up like this:
I managed to pin point the issue to the last line:
There wasn't an image selected in the back office causing the issue!
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.