-1

I am writing C# on Umbraco CMS, then Microsoft Visual Studio detects that I should handle the stackoverflow error on

var umbracoHelper = new Umbraco.Web.UmbracoHelper(Umbraco.Web.UmbracoContext.Current);
Image = umbracoHelper.Media(imageId).GetCropUrl("umbracoFile", "image");

How I can handle this issue? You can see the full code on this link. https://drive.google.com/open?id=0B6cMfQEoDEfwdnczSDRJakJIMzA

Umbraco version 7.2.8

Tool: Microsoft Visual Studio 2013

HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47
user41065
  • 27
  • 1
  • 4
  • 1
    What is `Image`? Is it a property? Show us the declaration. – Yuval Itzchakov Sep 24 '15 at 11:08
  • 1
    debugger may not always tell you where exactly the problem is. because its hard to detect this problem. do you use recursion call? – M.kazem Akhgary Sep 24 '15 at 11:10
  • 2
    if it's an `StackOverflowException` then you cannot catch/handle it ... it's one of those special *panic* exceptions ;) – Random Dev Sep 24 '15 at 11:28
  • You came to right place if you'd like to deal with `StackOverflow` exception ;) but we need more info – Fabjan Sep 24 '15 at 11:37
  • " Microsoft Visual Studio detects that I should handle the stackoverflow error": Does that mean you encounter one when you run the program? A stack overflow is nothing to handle but something to avoid. It usually happens because a function calls itself, directly or indirectly. – Peter - Reinstate Monica Sep 24 '15 at 11:42
  • 1
    You can't "handle" a stack overflow, you must fix the bug instead. The location where the exception is raised is rarely the exact location of the bug. – Hans Passant Sep 24 '15 at 11:57
  • possible duplicate of [How do I prevent and/or handle a StackOverflowException?](http://stackoverflow.com/questions/206820/how-do-i-prevent-and-or-handle-a-stackoverflowexception) – Frank J Sep 24 '15 at 13:42
  • @YuvalItzchakov I have pasted the link of full code. – user41065 Sep 25 '15 at 03:10
  • @Fabjan I have put the link of full code – user41065 Sep 25 '15 at 03:11

1 Answers1

2

I don't have the necessary reputation to be able to comment on your original question hence this "answer" - so I apologise in advance.

There's nothing in your code example that would throw StackOverflowException around the lines you've indicated, so you need to look deeper. You might possibly get a NullReferenceException on the GetCropUrl() extension method though as you haven't tested to make sure the meda item returns a valid object.

So everyone else doesn't have to download it - here's your code snippet (minus the usings/namespace):

public class Case
{
    public Case(IPublishedContent content) 
    {
        Id = content.Id;
        Description = content.GetPropertyValue<string>("description");
        Title = content.GetPropertyValue<string>("title");

        //image
        string image = content.GetPropertyValue<string>("image");            
        int imageId = 0;
        int.TryParse(image, out imageId);
        if (imageId != 0)
        {

                var umbracoHelper = new Umbraco.Web.UmbracoHelper(Umbraco.Web.UmbracoContext.Current);
                Image = umbracoHelper.Media(imageId).GetCropUrl("umbracoFile", "image");          
        }



        //Team
        string teamID = content.GetPropertyValue<string>("teamMember");
        Team = DAL.GetTeamProperties(teamID);
    }

    public Case() { }
    public int Id { get; set; } 
    public string Title { get; set; }            
    public string Description { get; set; }
    public string Image { get; set; }
    public List<Team> Team { get; set; }
}

It's more likely that your problem lies here rather than the code extracting the Image Url:

Team = DAL.GetTeamProperties(teamID);

However more information is needed - can you post the actual stack trace of the exception?

Robert Foster
  • 2,317
  • 18
  • 28