Cybercop
Cybercop

Reputation: 8674

MVC: An unhandled exception of type 'System.StackOverflowException' occurred in System.Core.dll

This is my main layout of the application

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title - My ASP.NET Application</title>
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")

</head>
<body>
    <div class="navbar navbar-inverse navbar-fixed-top bs-docs-nav" role="banner">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                @Html.ActionLink("Date Picker", "Index", "Home", null, new { @class = "navbar-brand" })
            </div>
            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    <li>@Html.ActionLink("Home", "Index", "Home")</li>
                    <li>@Html.ActionLink("About", "About", "Home")</li>
                    <li>@Html.ActionLink("Contact", "Contact", "Home")</li>
                </ul>
                @Html.Partial("_LoginPartial")

            </div>
        </div>
    </div>

    @if (User.Identity.IsAuthenticated)
    {
        <div class="row">
            <div class="col-md-3">
                <div class="bs-sidebar hidden-print affix" role="complementary">
                    <ul class="nav bs-sidenav">                       
                        <li class="active">
                            @Html.ActionLink("Address Book","Index","AddressBook")
                            <ul class="nav">                              
                                <li>
                                    @Html.ActionLink("Add Contact", "AddPerson", "AddressBook")
                                </li>                               
                            </ul>
                        </li>
                        <li>
                            @Html.ActionLink("App", "Create", "Appointment")                           
                        </li>
                        <li>
                            @Html.ActionLink("myconn", "Index", "Connection")//error when I click this link.                     
                        </li>
                    </ul>
                </div>
            </div>
        </div>      
    }
    <div class="container body-content">
        @RenderBody()
        <hr />
        <footer>
            <p>&copy; @DateTime.Now.Year - MyApp</p>
        </footer>
    </div>

    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrap")
    @RenderSection("scripts", required: false)
</body>
</html>

I get the sidebar when the user is logged in, all the links work in sidebar except

@Html.ActionLink("myconn", "Action", "Controller")   

When I click the link called SuperOffice browser link changes to http://localhost:14834/Connection but I get error: in visual studio saying

An unhandled exception of type 'System.StackOverflowException' occurred in System.Core.dll

Here is my controller code

[Authorize]
public class Controller : Controller
{
    private readonly IConnectionRepository _connectionRepository;

    public ConnectionController(IConnectionRepository connectionRepository)
    {
        _connectionRepository = connectionRepository;
    }
}

When I put breakpoint in Index method of Connection controller, and click the SuperOffice link, I don't even get to that method. Any idea what is happening? I find it strange that all the link are working and I get forwarded to controller and all thing works perfect except that one.

Upvotes: 2

Views: 11556

Answers (2)

DarthVader
DarthVader

Reputation: 55032

You probably have [Authorize] attribute somewhere that is giving you stackoverflow.

Upvotes: 1

MustafaP
MustafaP

Reputation: 6633

    var hasSuperOfficeConnection = _connectionRepository.CheckIfSuperOfficeIsConnected(userId);
    var model = new Index
    {
        IsSuperOfficeConnected = hasSuperOfficeConnection
    };

I think there is a infinite loop here If you can give more code (ie IsSuperOficeConnected) we can help you more

public class ConnectionRepository:IConnectionRepository
{
    private readonly DatePickerDbContext _db;
    //private readonly ISuperOfficeRepository _superOfficeRepository;

    public ConnectionRepository(DatePickerDbContext db)//, ISuperOfficeRepository superOfficeRepository
    {
        _db = db;
      //  _superOfficeRepository = superOfficeRepository;
    }
     public int GetConnectionId(string connectionName)
     {
        var connection = _db.Connections.Single(c => c.Name == connectionName);
        return connection.Id;
      }

     public bool CheckIfSuperOfficeIsConnected(string userId)
     {
        var connectionId = GetConnectionId("SuperOffice");
        var result = _db.UserConnections.Where(uc => uc.UserId == userId && uc.ConnectionId == connectionId);
        return result.Any();
     }
 }

Upvotes: 0

Related Questions