AspNetCore 2.0 crashing when calling EntityFrameWork core (Overflow Exception)

1

I have had this problem for a while now, and have talked to Microsoft about it, with no solution so far. Now I have reproduced the error in a brand new project. I have removed all unnessary code, and this code is still giving me the error:

System.StackOverflowException occurred
  HResult=0x800703E9
  Source=<Cannot evaluate the exception source>
  StackTrace:
<Cannot evaluate the exception stack trace>

My project consists of a Startup.cs class with this content:

public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddDbContext<FrilivDB>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")).EnableSensitiveDataLogging());
        services.AddMvc();
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        app.UseMvc(routes =>
        {
            routes.MapRoute(name: "default", template: "{controller=Home}/{action=Index}/{id?}");
            routes.MapRoute("ViewProduct", "{brand}/{productTitle}", defaults: new { controller = "Products", action = "Details" });
        });
    }
}

My Productscontroller looks like this:

public class ProductsController : Controller
{
    private readonly FrilivDB _context;

    public ProductsController(FrilivDB context)
    {
        _context = context;
    }

    public async Task<IActionResult> Details(string brand, string productTitle)
    {
        var product = _context.Products.Select(p => p.Title);
        return View();
    }
}

And when passing by this line in the debugger the error occurs:

var product = _context.Products.Select(p => p.Title);

The error occurs after waiting between 15 and 30 seconds, every time. Any one has any ideas or experienced the same thing?

This is what I see in the Output window:

    AO.Shop>       Request starting HTTP/1.1 GET http://localhost:44317/tatonka/alaska  
AO.Shop> info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
AO.Shop>       Request starting HTTP/1.1 GET http://localhost:44317/tatonka/alaska  
AO.Shop> info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
AO.Shop>       Executing action method AO.Shop.Controllers.ProductsController.Details (AO.Shop) with arguments (tatonka, alaska) - ModelState is Valid
AO.Shop> info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
AO.Shop>       Executing action method AO.Shop.Controllers.ProductsController.Details (AO.Shop) with arguments (tatonka, alaska) - ModelState is Valid
AO.Shop> 
AO.Shop> Process is terminating due to StackOverflowException.
c#
entity-framework
asp.net-core
asp.net-core-2.0
asp.net-core-mvc-2.0
asked on Stack Overflow Sep 7, 2017 by Axel Andersen • edited Jan 30, 2018 by Nkosi

2 Answers

4

After a lot of comminication with Microsoft and a whole lot of debugging and commenting code in and out, I found the problem.

It was due to poor DB settings. I had 4 tables in my DB which were referencing them selves as Foreign keys, that gave a Stackoverflow Exception from the EF Core.

After removing all 4 and rebuilding the entire Model, it worked. Thanks for your input

answered on Stack Overflow Sep 26, 2017 by Axel Andersen
-1

Add one or more try-catch statements to get more information about the exception being generated. Then use that information to update your code to prevent the exception from occurring.

Also, consider reviewing the patches that Microsoft has for ASP.NET 2.0. This ASP.NET 2.0 hotfix rollup package page references some issues that may apply to your problem. Another option is to upgrade to ASP.NET 3.5+, but I presume that you are trying to avoid that approach.

I hope this helps.

answered on Stack Overflow Sep 7, 2017 by JohnH • edited Sep 8, 2017 by JohnH

User contributions licensed under CC BY-SA 3.0