Null reference exception on Themes in 2.5 RC

Topics: Themes
Jun 21, 2011 at 5:24 AM

Hello,

When I select the Themes tab on the Settings admin page, I'm getting the following error.  Any ideas?  Thanks!

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 55:         <div>
Line 56:             @if (tab == "1"){
Line 57:                 @Helpers.AdminHelper.InstalledThemes()
Line 58:             }
Line 59:             else{


Source File: c:\Sites\brianpeek.com\blogengine.web\admin\Settings\Themes.cshtml Line: 57

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
   ASP.Helpers.AdminHelper.<InstalledThemes>b__3(TextWriter __razor_helper_writer) +289
   ASP._Page_admin_Settings_Themes_cshtml.Execute() in c:\Sites\xxx.com\blogengine.web\admin\Settings\Themes.cshtml:57
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +279
   System.Web.WebPages.WebPage.ExecutePageHierarchy() +335
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +156
   System.Web.WebPages.WebPageHttpHandler.ProcessRequestInternal(HttpContext context) +299

Coordinator
Jun 21, 2011 at 8:18 AM

It's nice you provided these error details .... but I'm not sure exactly why the error is occurring, I cannot reproduce it.

If you go into the Extension pages in the control panel, and click around there, do you get similar errors?  The Themes page and the Extension pages are both Razor pages.  Trying to see if it's a Razor problem in general, or something specific to that Helpers.AdminHelper.InstalledThemes() line of code.  How about the Dashboard -- that too is a Razor page, any errors there?

You could try (as a test) temporarily changing that code on line 57 to the following just to see if you get past the error (the line of code comes from the dashboard).

@Helpers.DashboardHelper.GetStats()

Jun 21, 2011 at 3:25 PM

I was getting the same error on my local machine.  I found that when I gave the IIS_IUSRS group Full Control on the Themes directory, the problem went away.  I'm running on Win7.

Jun 21, 2011 at 3:32 PM

Giving full control on this directory to NETWORK SERVICE (app pool user) did the trick here as well.  @BenAmada, would you still like me to change the line above?

Thanks!

Coordinator
Jun 21, 2011 at 4:21 PM

Good catch. Error is because BE trying to write default theme.xml file and themes directory is read only. We'll handle this error for final release, thanks for bringing it up.

Jul 7, 2011 at 8:41 AM

I've got the same problem. I can't give a full control since i dont have access to that option in my control panel. I just upgraded my blog to 2.0.5 from 2.0.0. If i change that line of code with this one 

"@Helpers.DashboardHelper.GetStats()" error is gone. What should i do?

Coordinator
Jul 7, 2011 at 10:50 AM

Changing it to @Helpers.DashboardHelper.GetStats() is not the solution -- that was just a meaningless test to see if the problem was with Extensions, or Razor syntax, etc.

This was reported during the BE 2.5 Release Candidate time, and I *thought* (but could be wrong) that a change was made to prevent this error from happening.

You do need to give Write Permissions to the App_Data folder for BE to run.  Were you able to set Write Permissions on that folder?  If so, it seems like you should be able to set Write Permissions on the Themes directory too.  You can probably ask your webhost via a support request to open up Write permissions on that Themes folder ... if the option isn't available in the control panel.

Jul 7, 2011 at 9:36 PM

Thank you for fast response.

Well, i can't give write permissions and i know it is not your fault at all. This is response from my webhost about write permission http://somee.com/doka/DoHelpTopics.aspx?docode=false&thnid=104). That's why i'm using SQL database instead of .xml.

I just want to change theme so is there any other way to change it?

I

Coordinator
Jul 8, 2011 at 8:53 AM

As a workaround, you can remove @Helpers.AdminHelper.InstalledThemes() to eliminate the error, and then to change themes ... if you don't already have the theme, download the theme and put it into the /themes/ folder.  And then to change to that theme, in the be_Settings DB table, there is a setting with a name of "theme".  You'll want to update the value of that setting to the name of the theme you want.  After doing this, restarting the blog will be necessary so the old settings cached in memory will get cleared out and the updated settings will be read from the DB.  You can restart the blog by making any change to the web.config file (add a space, etc).