SQL Server Getting System.StackOverFlowException with Entity Framework

pu3pd22g  于 2023-08-02  发布在  其他
关注(0)|答案(1)|浏览(103)

Bit of a weird one this. Checked everything in working last night and went to bed as you do. Now at this point I will mention I am a team of one and there is no one else working on this!

Got up this morning to pick up where I left of and now I get System.StackOverFlow exception in ModelContainer.cs . Absolutely nothing has changed from last night.

The Dev PC is Windows 11. Database server is Windows Server 2019 running SQL Server 2022. Visual Studio 2022. Everything is fully patched to the latest versions.

This is the call I am making to the API:

A screenshot showing exactly where the error is thrown:

And this is the code for the thing I am calling (the GET) :

namespace Phoenix.Server.Web.Api.Base.Controllers
{
    [RoutePrefix("api/account")]
    public class AccountController : ApiController 
    {
        private AccountService _accountService = new AccountService();

        // GET api/account
        public string Get()
        {
            return "The beast is alive!!";
        }

        // POST api/account/create
        [Route("create")]
        public string Create([FromBody] AccountCreationFullRequest request)
        {
            return _accountService.CreateAccount(request);
        }
    }
}

Text version of the model as requested:

public partial class ModelContainer : DbContext
{
    public ModelContainer()
        : base("name=ModelContainer")
    {
    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        throw new UnintentionalCodeFirstException();
    }

    public virtual DbSet<AppSetting> AppSettings { get; set; }
    public virtual DbSet<County> Counties { get; set; }
    public virtual DbSet<Country> Countries { get; set; }
    public virtual DbSet<DatabaseVersion> DatabaseVersions { get; set; }
    public virtual DbSet<DocumentData> DocumentDatas { get; set; }
    public virtual DbSet<DocumentIndex> DocumentIndexes { get; set; }
    public virtual DbSet<DocumentType> DocumentTypes { get; set; }
    public virtual DbSet<EmailAddress> EmailAddresses { get; set; }
    public virtual DbSet<EventLog> EventLogs { get; set; }
    public virtual DbSet<EventSource> EventSources { get; set; }
    public virtual DbSet<EventType> EventTypes { get; set; }
    public virtual DbSet<Log> Logs { get; set; }
    public virtual DbSet<Password> Passwords { get; set; }
    public virtual DbSet<Pepper> Peppers { get; set; }
    public virtual DbSet<Permission> Permissions { get; set; }
    public virtual DbSet<Person> Persons { get; set; }
    public virtual DbSet<PostalAddress> PostalAddresses { get; set; }
    public virtual DbSet<Role> Roles { get; set; }
    public virtual DbSet<Salt> Salts { get; set; }
    public virtual DbSet<TelephoneNumber> TelephoneNumbers { get; set; }
    public virtual DbSet<User> Users { get; set; }
    public virtual DbSet<UserSession> UserSessions { get; set; }
    public virtual DbSet<UsersToPassword> UsersToPasswords { get; set; }
    public virtual DbSet<UserType> UserTypes { get; set; }
}

Last night the beast was alive - this morning its seems to have had a heart attack!

Any help greatly appreciated - there isn't enough coffee in the world for this madness on a Sunday

0sgqnhkj

0sgqnhkj1#

You need to check a few things here. You may have not realised it yesterday but there will be an issue before as well if you have not made any code changes.

  • You have to put breakouts and debug your code.
  • Review your code and see if there are any loops running infinitely.
  • You also need to check your recursive calls as well in your project.
  • You also need to verify whether there are any circular dependencies or recursive relationships (or self-referencing relationships) within your entity classes in your database configuration.
  • I am not sure but you can try commenting on this line throw new UnintentionalCodeFirstException();
  • I would also suggest commenting on a line one by one in your ModelContainer for entities and checking which entity is causing this issue. You also need to make sure that you have not accidentally deleted anything from the database. Read the official documentation , you might get some idea of the root cause.

相关问题