Copied to clipboard

Flag this post as spam?

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


  • Lee 1130 posts 3088 karma points
    Jun 22, 2015 @ 10:56
    Lee
    0

    IUrlProvider - Cannot evaluate expression because the current thread is in a stack overflow state

    I have implemented an IUrlProvider to change a node url, but now I can't run the site and when I debug I get the following error?

    Cannot evaluate expression because the current thread is in a stack overflow state

    Anyone else had this with an IUrlProvider?

  • Lee 1130 posts 3088 karma points
    Jun 22, 2015 @ 11:04
    Lee
    0

    Should have said I am registering it like so

    UrlProviderResolver.Current.InsertTypeBefore<DefaultUrlProvider, ServiceUrlProvider>();
    
  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Jun 22, 2015 @ 11:10
    Tim
    1

    Can you post the code for the UrlProvider? The issue appears to be there I think.

  • Lee 1130 posts 3088 karma points
    Jun 22, 2015 @ 11:34
    Lee
    0

    I have just changed it and still get the same error. I have this in application starting.

            UrlProviderResolver.Current.InsertType<ServiceUrlProvider>();
    

    And this is my ServiceUrlProvider

    public class ServiceUrlProvider : DefaultUrlProvider
    {
        public override string GetUrl(UmbracoContext umbracoContext, int id, Uri current, UrlProviderMode mode)
        {
            var content = umbracoContext.ContentCache.GetById(id);
            if (content.DocumentTypeAlias == "Service" && content.Parent != null)
            {
                // Get the last part of the url
                var currentUrl = content.Url;
                var splitSections = currentUrl.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                return string.Concat("/",splitSections.Last(), "/");
            }
            return base.GetUrl(umbracoContext, id, current, mode);
        }
    }
    

    But I just keep getting the StackOverFlow exception... ?

  • Carl Jackson 139 posts 478 karma points
    Jun 22, 2015 @ 11:36
    Carl Jackson
    100

    Is it by any chance thaat

    var currentUrl = content.Url;
    

    is recursively calling your service?

    Thanks

    Carl.

  • Lee 1130 posts 3088 karma points
    Jun 22, 2015 @ 11:39
    Lee
    0

    Well this is awkward lol. Thanks Carl. I thought I had changed that to

    base.GetUrl(umbracoContext, id, current, mode);
    

    But too blindly changing things!! Thanks.

  • Doron Uziel 23 posts 93 karma points
    Jun 22, 2015 @ 11:44
    Doron Uziel
    0

    I think that Carl is correct, I would replace it with

    var currentUrl=base.GetUrl(umbracoContext, id, current, mode);
    
Please Sign in or register to post replies

Write your reply to:

Draft