简体   繁体   English

我们如何处理stackoverflow异常C#

[英]How can we handle the stackoverflow exception C#

I am writing C# on Umbraco CMS, then Microsoft Visual Studio detects that I should handle the stackoverflow error on 我在Umbraco CMS上编写C#,然后Microsoft Visual Studio检测到我应处理以下内容的stackoverflow错误

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 https://drive.google.com/open?id=0B6cMfQEoDEfwdnczSDRJakJIMzA

Umbraco version 7.2.8 Umbraco版本7.2.8

Tool: Microsoft Visual Studio 2013 工具:Microsoft Visual Studio 2013

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. 在您的代码示例中,没有什么会导致您在所指示的行周围抛出StackOverflowException的,因此您需要更深入地研究。 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. 您可能可能会在GetCropUrl()扩展方法上收到NullReferenceException,尽管您尚未进行测试以确保meda项返回有效对象。

So everyone else doesn't have to download it - here's your code snippet (minus the usings/namespace): 因此,其他所有人都无需下载它-这是您的代码段(减去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: 您的问题更有可能出在这里,而不是代码提取Image Url:

Team = DAL.GetTeamProperties(teamID);

However more information is needed - can you post the actual stack trace of the exception? 但是,需要更多信息-您可以发布异常的实际堆栈跟踪吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM