1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Bugs & Issues / Null reference error from using URL routing

Null reference error from using URL routing

15 posts, 0 answered
  1. David
    David avatar
    7 posts
    Registered:
    22 Aug 2011
    22 Dec 2011
    Link to this post
    I implemented the URL routing example mentioned in http://www.sitefinity.com/devnet/forums/sitefinity-4-x/developing-with-sitefinity/url-routing.aspx. I just upgraded from Sitefinity 4.2 to 4.4, and now I'm getting the following error for any URL using the custom route:

    [NullReferenceException: Object reference not set to an instance of an object.]
       Telerik.Sitefinity.Web.PageRouteHandler.SetPageCacheDependencies() +476
       Telerik.Sitefinity.Web.PageRouteHandler.handler_Unload(Object sender, EventArgs e) +35
       System.Web.UI.Control.OnUnload(EventArgs e) +8885382
       System.Web.UI.Control.UnloadRecursive(Boolean dispose) +241
       System.Web.UI.Page.UnloadRecursive(Boolean dispose) +23
       System.Web.UI.Page.ProcessRequestCleanup() +43
       System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +253
       System.Web.UI.Page.ProcessRequest() +78
       System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
       System.Web.UI.Page.ProcessRequest(HttpContext context) +49
       ASP.sfpageservice_a8f63540_de1e_4cb4_a407_639ae23f329d_6_basic_en_aspx.ProcessRequest(HttpContext context) in c:\Users\{myusername}\AppData\Local\Temp\Temporary ASP.NET Files\root\0d1a8e78\d1015611\App_Web_a8f63540-de1e-4cb4-a407-639ae23f329d_6_basic_en.aspx.d63928b6.hgexzo4u.0.cs:0
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +100
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

    I am able to navigate to the real page (not using the routing) without problem, but I get this error for any URL which uses the custom route. 

    I'm guessing something isn't being set, but I cannot find anything further. As I mentioned, we went directly from Sitefinity 4.2 to 4.4, so I'm not sure if this was caused by 4.3 or 4.4. 

    Any ideas?

    Thanks,
    David
  2. UXP-IT
    UXP-IT avatar
    2 posts
    Registered:
    16 Apr 2008
    23 Dec 2011
    Link to this post
    Exactly the same problem. Does anybody know a fix for this?

    Thanks in advance,

    Kevin Sars
  3. Lubomir Velkov
    Lubomir Velkov avatar
    688 posts
    Registered:
    03 Nov 2014
    27 Dec 2011
    Link to this post
    Hi Kevin and David,

    Does this exception occur after executing some line of code from your custom route handler or does it happen before you enter the GetRouteData() method?

    Regards,
    Lubomir Velkov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  4. UXP-IT
    UXP-IT avatar
    2 posts
    Registered:
    16 Apr 2008
    28 Dec 2011
    Link to this post
    Hi Lubomir,

    We have found out that when you use the "App.WorkWith().Pages().Get()" method in a thread, you will encounter a null reference exeption.
    Is it possible that the method uses an instance of Page? 

    The null reference exeption reported above occurs after Sitefnity executes "Telerik.Sitefinity.Web.PageRouteHandler.SetPageCacheDependencies()".
    Maybe the information beneath can help you further:

    (((System.Web.HttpApplication)(sender)).Context.Error).StackTrace
     
     at Telerik.Sitefinity.Web.PageRouteHandler.SetPageCacheDependencies()
       at Telerik.Sitefinity.Web.PageRouteHandler.handler_Unload(Object sender, EventArgs e)
       at System.Web.UI.Control.OnUnload(EventArgs e)
       at System.Web.UI.Control.UnloadRecursive(Boolean dispose)
       at System.Web.UI.Page.UnloadRecursive(Boolean dispose)
       at System.Web.UI.Page.ProcessRequestCleanup()
       at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
       at System.Web.UI.Page.ProcessRequest()
       at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
       at System.Web.UI.Page.ProcessRequest(HttpContext context)
       at ASP.sfpageservice_2128fa5d_03b3_416b_8bea_21d8666bdd98_2_vinites_aspx.ProcessRequest(HttpContext context) in c:\Users\userName\AppData\Local\Temp\Temporary ASP.NET Files\root\94d62d5f\300c1492\App_Web_2128fa5d-03b3-416b-8bea-21d8666bdd98_2_project.aspx.d63928b6.hdu7p3wo.0.cs:line 0
       at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
       at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)


    Thanks in advance,

    Kevin Sars

  5. Lubomir Velkov
    Lubomir Velkov avatar
    688 posts
    Registered:
    03 Nov 2014
    30 Dec 2011
    Link to this post
    Hi Kevin,

    Could you please clarify a bit - what do you mean by "a thread" ? Do you create a new thread using the System.Threading namespace? I also couldn't understand the following question - "Is it possible that the method uses an instance of Page" ? Could you try changing the logic to not use the Fluent API - App.WorkWith().etc but use the PageManager instead -

    var manager = PageManager.GetManager();
    var pages = manager.GetPageNodes().
    etc.

    Kind regards,
    Lubomir Velkov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. David
    David avatar
    7 posts
    Registered:
    22 Aug 2011
    03 Jan 2012
    Link to this post
    The exception occurs after the GetRouteData() method. I checked one page that uses several user controls, and those controls appear to execute fully and correctly. The exception does not appear to be thrown from any custom code. It appears to be from within the Sitefinity engine.

    For instance, when I'm debugging the site, the exception is not shown from any specific line of code. In fact the "Source Error" section of the error page states "No relevant source lines". 

    Thanks again,
    David
  7. Lubomir Velkov
    Lubomir Velkov avatar
    688 posts
    Registered:
    03 Nov 2014
    05 Jan 2012
    Link to this post
    Hi David,

    I tried your code and registered it in Global.asax.cs with

    RouteTable.Routes.Insert(1, new CustomSitefinityRoute());

    Now I always enter in the GetRouteData method, even if I do not access a URL like ~/features - but this is normal. I don't get such exception. I'm using a new 4.4 project. Could you try if your code works on a non upgraded 4.4 project? Also, how do you register the custom handler in the RouteTable?

    Kind regards,
    Lubomir Velkov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. David
    David avatar
    7 posts
    Registered:
    22 Aug 2011
    05 Jan 2012
    Link to this post
    Hi Lubomir,

    I am able to re-create this error in a new 4.4 project. Here's what I did:

    1. Create a new 4.4 project
    2. Created a new page with the name "home", which was the home page. (Guessing this isn't necessary)
    3. Created a second page with the name "prices", with the url /prices.
    4. Added CustomSitefinityRoute class:
    public class CustomSitefinityRoute : SitefinityRoute
    {
        public override System.Web.Routing.RouteData GetRouteData(HttpContextBase httpContext)
        {
            //get the path from the httpContext variable and parse it
            var virtuallPath = this.GetVirtualPathInternal(httpContext);
            if (virtuallPath.Contains("features"))
            {
                //parse the acutal path to find the PageSiteNode from the sitemap provider
                var sitemapProvider = this.GetSiteMapProvider();
                if (sitemapProvider == null)
                    return null;
                bool isAdditional;
                string[] pars;
                var node = sitemapProvider.FindSiteMapNode("/prices", false, out isAdditional, out pars);
                if (node != null)
                    return this.GetRouteDataInternal(pars, httpContext.Request.QueryString, node);
            }
     
            return base.GetRouteData(httpContext);
        }
     
        public static void RegisterType()
        {
            ObjectFactory.Container.RegisterType<SitefinityRoute, CustomSitefinityRoute>();
        }
    }

    (this redirects /features to /prices)

    5.Updated Global.asax:
    protected void Application_Start(object sender, EventArgs e)
    {
        Telerik.Sitefinity.Services.SystemManager.ApplicationStart += new EventHandler<EventArgs>(SystemManager_ApplicationStart);
    }
     
    void SystemManager_ApplicationStart(object sender, EventArgs e)
    {
        CustomSitefinityRoute.RegisterType();
        RouteTable.Routes.Insert(1, new CustomSitefinityRoute());
    }

    6. Opened site and navigated to http://localhost:60876/features

    I then get the same error. If I navigate to the real URL (http://localhost:60876/prices), it works fine. 

    Are you now able to re-create this problem?

    Thanks again,
    David
  9. Lubomir Velkov
    Lubomir Velkov avatar
    688 posts
    Registered:
    03 Nov 2014
    09 Jan 2012
    Link to this post
    Hi David,

    I'm getting a little confused. I followed your instructions exactly but didn't get any exception. Also if I may suggest something - in Global.asax use the following code:

    Bootstrapper.Initialized += new EventHandler<Telerik.Sitefinity.Data.ExecutedEventArgs>(Bootstrapper_Initialized);

    and then

    void Bootstrapper_Initialized(object sender, Telerik.Sitefinity.Data.ExecutedEventArgs e)
    {
        CustomSitefinityRoute.RegisterType();
        if (e.CommandName == "RegisterRoutes")
        {
            RouteTable.Routes.Insert(1, new CustomSitefinityRoute());
        }
    }

    Regards,
    Lubomir Velkov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  10. David
    David avatar
    7 posts
    Registered:
    22 Aug 2011
    09 Jan 2012
    Link to this post
    I implemented those changes in the Global.asax, and I'm still getting the error.

    What are my options? I can zip up my project and database. Or is there some way to figure out what's happening in the Telerik.Sitefinity.Web.PageRouteHandler.SetPageCacheDependencies  method?
  11. Lubomir Velkov
    Lubomir Velkov avatar
    688 posts
    Registered:
    03 Nov 2014
    11 Jan 2012
    Link to this post
    Hi David,

    I think it would be best if you zipped your project and database and sent it to us. That way we will be able to reproduce the problem locally and by debugging with the source code we'll be able to see why is this exception happening. If you wish you could open a separate support ticket and send the files or download details there.

    Regards,
    Lubomir Velkov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  12. David
    David avatar
    7 posts
    Registered:
    22 Aug 2011
    11 Jan 2012
    Link to this post
    I have submitted a support ticker (500482) with the project and database attached. 
  13. Lubomir Velkov
    Lubomir Velkov avatar
    688 posts
    Registered:
    03 Nov 2014
    13 Jan 2012
    Link to this post
    Hello David,

    Okay, I suggest from now on to continue our communication on the matter in the support ticket.

    Greetings,
    Lubomir Velkov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  14. DSorre
    DSorre avatar
    1 posts
    Registered:
    18 Jul 2012
    26 Jan 2012
    Link to this post
    Was this ever resolved? I think it would be nice to post the solution for others :)

    Thanks!
  15. Lubomir Velkov
    Lubomir Velkov avatar
    688 posts
    Registered:
    03 Nov 2014
    31 Jan 2012
    Link to this post
    Hello Daniel,

    I believe we resolved one specific issue. This is the code that you need to add in your custom route handler -

    protected override SiteMapBase GetSiteMapProvider()
    {
        var siteMapProvider = base.GetSiteMapProvider();
        SystemManager.CurrentHttpContext.Items[SiteMapBase.ProviderKey] = siteMapProvider;
      
        return siteMapProvider;
    }

    I hope this helps.

    Regards,
    Lubomir Velkov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
15 posts, 0 answered