_rootForumNode is null when using ForumActiveTopics.ascx
When including the ForumActiveTopics.ascx in my homepage I'm getting an error. Debugging shows me _rootForumNode is null. Where should I set it? Cannot seem to find it browsing the sourcecode...
BTW my forum root != site root. Got this error after upgrading to 1.7
Server Error in '/' Application.
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 122: public IEnumerable ReturnActiveTopics(int amountToTake)
Line 123: {
Line 124: var topics = _rootForumNode.Descendants(AppConstants.NodeTypeTopic)
Line 125: .OrderByDescending(x => x.GetProperty("forumTopicLastPostDate").Value.ToDateTime());
Line 126:
[NullReferenceException: Object reference not set to an instance of an object.]
Umbraco.Web.PublishedContentExtensions.Descendants(IPublishedContent content, Func`2 func) +9
nForum.BusinessLogic.Data.ForumFactory.ReturnActiveTopics(Int32 amountToTake) in d:\Websites\nForum\nForum.BusinessLogic\Data\ForumFactory.cs:124
nForum.usercontrols.nForum.ForumActiveTopics.ShowActiveTopics() in d:\Websites\nForum\nForum\usercontrols\nForum\ForumActiveTopics.ascx.cs:23
nForum.usercontrols.nForum.ForumActiveTopics.Page_Load(Object sender, EventArgs e) in d:\Websites\nForum\nForum\usercontrols\nForum\ForumActiveTopics.ascx.cs:14
Well the UC won't find the forum as its below it. The forumRoot looks for AncesterOrSelf() as it assumes the pages will be under the forum so has no way of finding the forum root node.
I haven't tried this yet, but it should work for you
rootNode = cPage.AncestorOrSelf(AppConstants.ForumDocType);
if (rootNode == null)
{
// Means can't find it, so look down
rootNode = cPage.Descendants(AppConstants.ForumDocType).FirstOrDefault();
}
Can you post here if it works and I'll add it into the source as a backup for people.
_rootForumNode is null when using ForumActiveTopics.ascx
When including the ForumActiveTopics.ascx in my homepage I'm getting an error. Debugging shows me _rootForumNode is null. Where should I set it? Cannot seem to find it browsing the sourcecode...
BTW my forum root != site root. Got this error after upgrading to 1.7
Server Error in '/' Application.
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 122: public IEnumerable ReturnActiveTopics(int amountToTake) Line 123: { Line 124: var topics = _rootForumNode.Descendants(AppConstants.NodeTypeTopic) Line 125: .OrderByDescending(x => x.GetProperty("forumTopicLastPostDate").Value.ToDateTime()); Line 126:
Source File: d:\Websites\nForum\nForum.BusinessLogic\Data\ForumFactory.cs Line: 124
Stack Trace:
What version of Umbraco are you using? Also you say in your homepage, is the homepage the root of the forum?
Can you also show me a screen grab of your node tree and point out which is the forum node and where you have put your active topics usercontrol?
I'm using Umbraco 6.1.3.
Homepage is not the root of the forum, also has a 'non-forum' masterpage.
Any tips on what to look for while debugging are also welcome.
Well the UC won't find the forum as its below it. The forumRoot looks for AncesterOrSelf() as it assumes the pages will be under the forum so has no way of finding the forum root node.
Drop me an email on lee (at) webdesigncompany.co.uk and I'll send you an updated DLL which might solve your problem.
great I guess that's it. Could you point me out what line you changed? So that I can change it in my customized source?
rootNode = cPage.AncestorOrSelf(AppConstants.ForumDocType);
something like cPage.Parent.Descendant(AppConstants.ForumDocType); ?
I haven't tried this yet, but it should work for you
Can you post here if it works and I'll add it into the source as a backup for people.
this one works:
rootNode = cPage.Up().Descendants(AppConstants.ForumDocType).FirstOrDefault();
not sure if it is very robust/generic but works for me now...
Ok thanks
this one works too:
cPage.Sibling(AppConstants.ForumDocType);
thanks Lee!
Thanks Yannick - this worked for me too.
Had a series of forum functionality not firing, turns out they were ALL related to locating _rootForumNode.
I have a suggested solution to the problem. This is how I fixed it for my project.
1.) I added the following method to the UmbracoAppHelpers.cs file in nForum.BusinessLogic.
2.) Then I modified ForumFactory.cs in nForum.BusinessLogic.Data by adding these three lines
resulting in
3.) I then added a content picker property in the root node doctype with the alias of forumRoot
This way I can target the root node from the ui side.
Hope this is useful.
Great post Steve - I'm sure a lot of people will find this useful.
How about nForum 1.5? Is there any similar solution?
is working on a reply...