Copied to clipboard

Flag this post as spam?

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


  • Michal Koblasa 45 posts 139 karma points
    Dec 08, 2015 @ 14:18
    Michal Koblasa
    0

    Custom Url Provider - StackOverflowError

    Hello bros,

    i writing custom URL provider and i getting StackOverflowError when i try to access content cache. Using V7, do you have any ideas?

    Thank you

    Handler registration:

    public class CustomEventHandler : ApplicationEventHandler
    {
        protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            base.ApplicationStarting(umbracoApplication, applicationContext);
    
            UrlProviderResolver.Current.InsertTypeBefore<DefaultUrlProvider, CustomUrlProvider>();
        }
    }
    

    Url provider:

    public class CustomUrlProvider : IUrlProvider
    {
        public string GetUrl(UmbracoContext umbracoContext, int id, Uri current, UrlProviderMode mode)
        {
         var content = umbracoContext.ContentCache.GetById(id);//Here is stack overflow exception
         ...
        }
    }
    
  • Serge 12 posts 103 karma points
    Jan 11, 2016 @ 15:05
    Serge
    0

    Hi Michal.

    I had a similar issue when forgot to add a check for incoming document type in GetUrl. So my url provider returned something(not null) for every node.

    Hope that can help. Sergey.

  • Michal Koblasa 45 posts 139 karma points
    Jan 12, 2016 @ 10:05
    Michal Koblasa
    0

    Hello, thank you for suggestion. Here is my code of GetUrl - return null is included. Problem is, that after StackOverflowError is stoped proces with web, so next line of code is not hit.

        public string GetUrl(UmbracoContext umbracoContext, int id, Uri current, UrlProviderMode mode)
        {
            var content = umbracoContext.ContentCache.GetById(id);//Here stack overflow exception
            if (content != null && content.DocumentTypeAlias == "Serialsuccessiondetail")
            {
                var url = content.Url;
                if (!(url.EndsWith("/")))
                {
                        url += "/";
                    }
                    return url;
                }
                return null;
            }
    

    Thank you

  • Serge 12 posts 103 karma points
    Jan 12, 2016 @ 11:15
    Serge
    100

    We have multiple custom url providers. And StackOverflow exception was thrown in different providers randomly on the same line(umbracoContext.ContentCache.GetById) until I fixed mine. So the next line should be hit multiple times before the exception is thrown.

    Try to debug what url is returned. And is your content item published correctly and has a valid url? Sometimes content items don't have urls due to cache issues.

  • Michal Koblasa 45 posts 139 karma points
    Jan 12, 2016 @ 12:06
    Michal Koblasa
    0

    Thank you, i went for debugging and my noobish code ended in recursion.

  • Sotiris Filippidis 286 posts 1501 karma points
    Apr 21, 2016 @ 22:08
    Sotiris Filippidis
    1

    I'm a little late to the discussion, but I recently faced the same problem. I found the answer here.

    The problem is this line: var url = content.Url;. This recurses and eventually you have a stack overflow.

    In order to resolve this you have to inherit from DefaultUrlProvider and use base.GetUrl(umbracoContext, id, current, mode) instead of content.Url.

Please Sign in or register to post replies

Write your reply to:

Draft