Please help - Umbraco 8 not working on Production Server
It's 2am and I've been battling for hours trying to get my site working on my production server ready for a demo later on today.
It did work but for some reason it has just started erroring.
It works fine on my development machine so I decided to delete everything to do with the site on the production server and start again but no joy.
The database, site and permissions are exactly as the development machine but when I try to run the site I get
[NullReferenceException: Object reference not set to an instance of an object.]
Application.Core.Builders.ModelLogic.CreateMasterModel(IPublishedContent content) in D:\Websites\mysite\Application.Core\Builders\ModelLogic.cs:32
Application.Core.Builders.ModelLogic.CreateMasterModel() in D:\Websites\mysite\Application.Core\Builders\ModelLogic.cs:22
Application.Web.Controllers.Hijacks.HomeController.Index(ContentModel model) +58
lambda_method(Closure , ControllerBase , Object[] ) +141
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controlle....
What am I trying to do on line 32?
I'm trying to read the returned value of this code which just gets me the website root node.
public static SiteRoot Website(this IPublishedContent content, bool noCache = false)
{
var website = (SiteRoot)System.Web.HttpContext.Current.Items["Website"];
if (website == null || noCache)
{
website = content.AncestorOrSelf<SiteRoot>();
if (!noCache)
{
System.Web.HttpContext.Current.Items["Website"] = website;
}
}
return website;
}
The node definitely exists as I can access the Umbraco back-end fine but it's as if I'm not getting any content when I ask for it.
All works fine on the dev machine and I'm clueless about what is not working.
It depends a little where you are using your SiteRoot static method
If it's not in some code that's executing as part of a httprequest, then HttpContext.Current would be null?
eg if examine search indexes are building at startup on your new server and you have an event that refers to the SiteRoot, but it's happening on a background thread (or similar situation).
If it's still 2 oclock in the morning metaphorically, I'd remove your caching of SiteRoot, and just return it direct from Umbraco's published cache.
(when it's a bit after 2 o'clock in the morning - have a test using MiniProfiler (https://our.umbraco.com/documentation/Getting-Started/Code/Debugging/#miniprofiler) on how expensive a request it is to return it from Umbraco's cache - you may find it's not necessary to add the further layer of caching)
In my Umbraco 7 projects my models are compiled into the main project DLL and I just have to deploy that to the root bin folder.
I thought it would be the same here because likewise the models are part of the project and get compiled in but it would seem it works differently.
Still a little bit confused but at least it is now working.
But yes I agree, that doesn't seem right, the whole point of AppData mode is that the models are generated into your visual studio solution - you include them in your project from the AppData folder (did you include them in the project?) - this then gives you intellisense when writing your views for the generated models. When you build your project the models are compiled into your project dll - you don't have to generate models on your production server...
In my dev environment it is working as expected. The models are built and part of my project so I get the intelli-sense and they are compiled into my production DLL.
I think the fact that I copied over the ~/../Application.Models/Models/CmsModels/Generated DLLs was irrelevant. It was re-enabling Models Builder in the web.config that made it work.
For some reason when it is turned off it will not return content and cast it to those model objects. It results in the Object not set error.
The reason I turned it off in the first place on my production server is because upon going into the Settings => Models Builder section in the CMS it just showed the following error:
So I figured I don't need it so turn it off. I had no idea it would break the front end.
Again this is another problem that I need to sort out. This setting works fine on my dev machine as it creates the 'Application.Models' directory in the root of my website...
...but on the production server it goes up a level to wwwroot and tries to create them there where it does not have permission.
Maybe I just need to change the value of that setting on the production server.
No other appSettings need to be changed: you still need models builder enabled, you just don't want the models to be generated anywhere other than on dev where they get compiled into your DLLs.
And did you recently migrate to a newer version of Umbraco. Till Umbraco 8.6.6 things went fine but from 8.7.x onwards I also see changes in the behaviour of the ModelsBuilder (or ModelsBuilder.Embedded as it is now called).
I'm wondering if this change in behaviour is also related to this.
This was in 8.9. I had just upgraded before deploying to the production server for the first time.
My only experience of Models Builder previously was in Umbraco 7 and I used that in my project via the API. I had never used the Umbraco interface for it so had never turned it off before in the web.config.
Please help - Umbraco 8 not working on Production Server
It's 2am and I've been battling for hours trying to get my site working on my production server ready for a demo later on today.
It did work but for some reason it has just started erroring.
It works fine on my development machine so I decided to delete everything to do with the site on the production server and start again but no joy. The database, site and permissions are exactly as the development machine but when I try to run the site I get
What am I trying to do on line 32? I'm trying to read the returned value of this code which just gets me the website root node.
The node definitely exists as I can access the Umbraco back-end fine but it's as if I'm not getting any content when I ask for it.
All works fine on the dev machine and I'm clueless about what is not working.
Any ideas?
Thanks,
Matt
Hi Matt
It depends a little where you are using your SiteRoot static method
If it's not in some code that's executing as part of a httprequest, then HttpContext.Current would be null?
eg if examine search indexes are building at startup on your new server and you have an event that refers to the SiteRoot, but it's happening on a background thread (or similar situation).
If it's still 2 oclock in the morning metaphorically, I'd remove your caching of SiteRoot, and just return it direct from Umbraco's published cache.
(when it's a bit after 2 o'clock in the morning - have a test using MiniProfiler (https://our.umbraco.com/documentation/Getting-Started/Code/Debugging/#miniprofiler) on how expensive a request it is to return it from Umbraco's cache - you may find it's not necessary to add the further layer of caching)
regards
Marc
Thanks for the reply Marc.
I've managed to fix it by deploying my Models Builder directory to the server. My Models Builder is configured as...
In my Umbraco 7 projects my models are compiled into the main project DLL and I just have to deploy that to the root bin folder. I thought it would be the same here because likewise the models are part of the project and get compiled in but it would seem it works differently. Still a little bit confused but at least it is now working.
Update: I've discovered the problem is down to turning off the models builder.
If it's on the site works fine.
This is not my expected behaviour as I don't want the production site to be generating models. I want it turned off.
Phew Matt
You'll sleep better tonight.
But yes I agree, that doesn't seem right, the whole point of AppData mode is that the models are generated into your visual studio solution - you include them in your project from the AppData folder (did you include them in the project?) - this then gives you intellisense when writing your views for the generated models. When you build your project the models are compiled into your project dll - you don't have to generate models on your production server...
regards
Marc
Hi Marc,
Yes, quite a relief to find the problem.
In my dev environment it is working as expected. The models are built and part of my project so I get the intelli-sense and they are compiled into my production DLL.
I think the fact that I copied over the ~/../Application.Models/Models/CmsModels/Generated DLLs was irrelevant. It was re-enabling Models Builder in the web.config that made it work. For some reason when it is turned off it will not return content and cast it to those model objects. It results in the Object not set error.
The reason I turned it off in the first place on my production server is because upon going into the Settings => Models Builder section in the CMS it just showed the following error:
So I figured I don't need it so turn it off. I had no idea it would break the front end.
Again this is another problem that I need to sort out. This setting works fine on my dev machine as it creates the 'Application.Models' directory in the root of my website...
...but on the production server it goes up a level to wwwroot and tries to create them there where it does not have permission. Maybe I just need to change the value of that setting on the production server.
Hi Matt,
I have the following settings in my local dev environment:
Which looks similar to the configuration you're using.
When deploying I change the ModelsMode appSetting value to Nothing:
No other appSettings need to be changed: you still need models builder enabled, you just don't want the models to be generated anywhere other than on dev where they get compiled into your DLLs.
Hope this helps!
Lotte
Ah thanks Lotte, that's great. It has fixed the error I was seeing on my production server.
It answers my follow up question. :-)
Kind regards,
Matt
Thanks for letting know your problem + solution.
May I ask what version of Umbraco are you using ?
And did you recently migrate to a newer version of Umbraco. Till Umbraco 8.6.6 things went fine but from 8.7.x onwards I also see changes in the behaviour of the ModelsBuilder (or ModelsBuilder.Embedded as it is now called).
I'm wondering if this change in behaviour is also related to this.
This was in 8.9. I had just upgraded before deploying to the production server for the first time.
My only experience of Models Builder previously was in Umbraco 7 and I used that in my project via the API. I had never used the Umbraco interface for it so had never turned it off before in the web.config.
is working on a reply...