5

プロジェクトにマイグレーションを追加しようとするたびにdotnetがクラッシュし、マイグレーションが作成されないという本当に面倒な問題が発生します。これは、dotnet ef migrations addAdd-Migrationのどちらを使用するかにかかわらず発生します。コマンドが実行を開始し、必要に応じてコンパイルが行われた後、StackOverflowExceptionでクラッシュします。デバッグには、次の情報が得られます。"dotnetが動作を停止しました"データベース移行を追加するときにStackOverflowExceptionが発生する

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

私のコンテキストは、そのオブジェクトエトセトラその複雑な性質やコレクション、と1つのint型のプロパティまたはすべてのオブジェクトを持っている1 Dbsetを持っている場合、それはまた、重要ではありません。マイグレーションとスナップショットを生成できる唯一のケースは、自分のコンテキストにDbSetsがない場合です。

.NET Coreのプレリリースバージョンとリリースバージョンの両方を試してみましたが、.NET Core SDK(旧バージョンがまだインストールされていたため)とVisual Studioを完全にアンインストールしてから再インストールしました。

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

と、次のように私のコンテキストは次のとおりです:私は、Windows 10 Proと私のモデルクラスにVisual Studioエンタープライズ2015.3を使用しています

は以下の通りです

public class LeagueContext : DbContext 
{ 
    public LeagueContext(DbContextOptions<LeagueContext> context) : base(context) 
    { 

    } 

    protected override void OnModelCreating(ModelBuilder modelBuilder) 
    { 

    } 

    public virtual DbSet<Player> Players { get; set; } 
} 

と私のサービスの構成:

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

私のproject.jsonは、リクエストに応じて:

{ 
    "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%" ] 
    } 
} 
+1

project.jsonを投稿して、すべての参照が適切であることを願ってください。 – Anuraj

+0

@Anuraj私は投稿に追加しました。 – Ceshion

+0

奇妙な。私のシステムでは問題なく動作しています。私はYomanによって生成されたASP.NET Web Appを使用しています。私はハードコードされた接続文字列を設定から読み込むよりも使用しています。あなたがdotnet.exeの1.0.0-preview2-003121バージョンを使用していることを願っています。 – Anuraj

答えて

0

私はそれを理解したと思う。 1つのプロパティを持つ1つのコレクションだけにコードをカットしていましたが、Add-Migrationを実行する前にコードを保存していないので、まだモデルの多くを使用していました。

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; } 
} 

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; } 
} 

確かに循環参照を持っている:何それは使用していたことは、このように見えました。私はなぜそれが考えられなかったのか分かりませんが、1対1の関係を設定する論理的な方法のように思えるのは、ちょっと奇妙だと思います。しかし、私は独立した側でForeignKey属性を使用しないことを覚えています。EFの仕組みだけです。

関連する問題