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
...
}
}
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;
}
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.
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:
Url provider:
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.
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.
Thank you
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.
Thank you, i went for debugging and my noobish code ended in recursion.
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.is working on a reply...