Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Yannick Smits 321 posts 718 karma points
    Sep 20, 2013 @ 16:57
    Yannick Smits
    0

    _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: 

    [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
  • Lee 1130 posts 3088 karma points
    Sep 20, 2013 @ 18:22
    Lee
    0

    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?

  • Yannick Smits 321 posts 718 karma points
    Sep 20, 2013 @ 18:40
    Yannick Smits
    0

     

    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.

     

     

  • Lee 1130 posts 3088 karma points
    Sep 20, 2013 @ 18:46
    Lee
    100

    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.

  • Lee 1130 posts 3088 karma points
    Sep 20, 2013 @ 18:53
    Lee
    0

    Drop me an email on lee (at) webdesigncompany.co.uk and I'll send you an updated DLL which might solve your problem.

  • Yannick Smits 321 posts 718 karma points
    Sep 20, 2013 @ 19:00
    Yannick Smits
    0

    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); ?

  • Lee 1130 posts 3088 karma points
    Sep 20, 2013 @ 19:03
    Lee
    0

    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.

  • Yannick Smits 321 posts 718 karma points
    Sep 20, 2013 @ 19:23
    Yannick Smits
    1

    this one works:

    rootNode = cPage.Up().Descendants(AppConstants.ForumDocType).FirstOrDefault();

    not sure if it is very robust/generic but works for me now... 

  • Lee 1130 posts 3088 karma points
    Sep 20, 2013 @ 19:24
    Lee
    0

    Ok thanks

  • Yannick Smits 321 posts 718 karma points
    Sep 20, 2013 @ 19:25
    Yannick Smits
    0

    this one works too:

    cPage.Sibling(AppConstants.ForumDocType);

    thanks Lee!

  • Steph Kyriakou 7 posts 27 karma points
    Feb 17, 2014 @ 06:54
    Steph Kyriakou
    0

    Thanks Yannick - this worked for me too.

    Had a series of forum functionality not firing, turns out they were ALL related to locating _rootForumNode.
     

     

     

  • Steve Miller 7 posts 29 karma points
    Mar 08, 2014 @ 01:13
    Steve Miller
    0

    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.

        public static int GetOverrideRootId()
        {
            int overrideRoot = -1;
    
            var cPage = CurrentForumPage();
            if (cPage != null)
            {
                IPublishedContentProperty forumRoot = cPage.GetProperty("forumRoot");
                if (forumRoot != null)
                    overrideRoot = cPage.GetProperty("forumRoot").Value.ToInt32();
            }
            return overrideRoot;
        }
    

    2.) Then I modified ForumFactory.cs in nForum.BusinessLogic.Data by adding these three lines

            if (overideRoot == null)
            {
                int forumRoot = UmbracoAppHelpers.GetOverrideRootId();
                if (forumRoot != -1) overideRoot = forumRoot;
            }
    

    resulting in

        public ForumFactory(int? overideRoot = null)
        {
            if (overideRoot == null)
            {
                int forumRoot = UmbracoAppHelpers.GetOverrideRootId();
                if (forumRoot != -1) overideRoot = forumRoot;
            }
            _rootForumNode = UmbracoAppHelpers.GetForumRootNode(overideRoot);
            _rootForumId = _rootForumNode != null ? _rootForumNode.Id : -1;
            //_rootForumId = ReturnRootForumId();
        }
    

    3.) I then added a content picker property in the root node doctype with the alias of forumRoot

    Content picker for selecting forum root node

    This way I can target the root node from the ui side.

    Hope this is useful.

  • Devin 87 posts 251 karma points
    Mar 18, 2014 @ 12:51
    Devin
    0

    Great post Steve - I'm sure a lot of people will find this useful.

  • Mirtan 1 post 21 karma points
    Apr 22, 2014 @ 12:55
    Mirtan
    0

    How about nForum 1.5? Is there any similar solution?

Please Sign in or register to post replies

Write your reply to:

Draft