"dotnet stopped working" StackOverflowException when adding database migration

I have a very annoying problem where every time I try to add a transition to my project, dotnet crashes and migrations are not created. This happens whether I dotnet ef migrations add or Add-Migration . The command starts to run, and if necessary, compilation occurs, and then it crashes using the StackOverflowException. Debugging provides the following information:

 Unhandled exception at 0x00007FFF798C97DE (coreclr.dll) in dotnet.exe: 0xC00000FD: Qaru (parameters: 0x0000000000000001, 0x000000AC03A75FF8). 

It also doesn't matter if my context has one Dbset whose objects have one int property or all objects with their complex properties and sets, etc. The only time I can create a hyphen and snapshot is if my context does not have DbSets.

I tried both the preliminary versions and the release of the .NET Core version, and also completely uninstalled the .NET Core SDK (since there were still old versions) and Visual Studio and reinstalled them.

I am using Visual Studio Enterprise 2015.3 for Windows 10 Pro, and my model class is below:

 public class Player { [Key] public int PlayerID { get; set; } } 

and my context is as follows:

 public class LeagueContext : DbContext { public LeagueContext(DbContextOptions<LeagueContext> context) : base(context) { } protected override void OnModelCreating(ModelBuilder modelBuilder) { } public virtual DbSet<Player> Players { get; set; } } 

and my service configuration:

 services.AddEntityFrameworkSqlServer().AddDbContext<LeagueContext>(config => { config.UseSqlServer(Configuration["ConnectionStrings:LeagueContext"]); }); 

My .json project, for:

 { "dependencies": { "Microsoft.NETCore.App": { "version": "1.0.0", "type": "platform" }, "Microsoft.AspNetCore.Diagnostics": "1.0.0", "Microsoft.AspNetCore.Mvc": "1.0.0", "Microsoft.AspNetCore.Razor.Tools": { "version": "1.0.0-preview2-final", "type": "build" }, "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0", "Microsoft.AspNetCore.StaticFiles": "1.0.0", "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", "Microsoft.Extensions.Configuration.Json": "1.0.0", "Microsoft.Extensions.Logging": "1.0.0", "Microsoft.Extensions.Logging.Console": "1.0.0", "Microsoft.Extensions.Logging.Debug": "1.0.0", "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0", "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0", "Microsoft.EntityFrameworkCore": "1.0.0", "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0", "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final", "Microsoft.EntityFrameworkCore.Design": "1.0.0-preview2-final" }, "tools": { "BundlerMinifier.Core": "2.0.238", "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final", "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final", "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final" }, "frameworks": { "netcoreapp1.0": { "imports": [ "dotnet5.6", "portable-net45+win8" ] } }, "buildOptions": { "emitEntryPoint": true, "preserveCompilationContext": true }, "runtimeOptions": { "configProperties": { "System.GC.Server": true } }, "publishOptions": { "include": [ "wwwroot", "Views", "Areas/**/Views", "appsettings.json", "web.config" ] }, "scripts": { "prepublish": [ "bower install", "dotnet bundle" ], "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ] } } 
+5
source share
1 answer

I think I figured it out. Although I shot down my code with only one collection with one property, I did not save it before running Add-Migration, so it still used more of the model. What he used looked like this:

 public class Player { [Key] public int PlayerID { get; set; } public int OrganizationID { get; set; } public int CurrentTeamID { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public DateTime JoinDate { get; set; } [ForeignKey("PlayerID")] public virtual PlayerAccount Account { get; set; } //[ForeignKey("PlayerID")] //public virtual PlayerCareer Career { get; set; } //[ForeignKey("PlayerID")] //public virtual PlayerInfo Info { get; set; } } 

and

 public class PlayerAccount { [Key] public int PlayerID { get; set; } public string Category { get; set; } public bool LeagueEmails { get; set; } public bool GameReminders { get; set; } [ForeignKey("PlayerID")] public virtual Player Player { get; set; } } 

which really has a circular link. I don’t know why I didn’t think about it, although I think it’s a little strange that the case is not being processed, especially since it seems like a logical way to establish a one-to-one relationship. However, I remember that I did not use the ForeignKey attribute on the independent side of how EF works.

0
source

All Articles