小编Ces*_*ion的帖子

添加数据库迁移时,"dotnet已停止工作"StackOverflowException

我有一个非常恼人的问题,每当我尝试向项目添加迁移时,dotnet崩溃并且不会创建迁移.无论我是否使用dotnet ef migrations add或,都会发生这种情况Add-Migration.命令开始运行并在必要时进行编译,然后崩溃并发生StackOverflowException.调试产生以下信息:

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

如果我的上下文有一个Dbset,其对象具有一个int属性,或者所有对象具有复杂属性和集合,则无关紧要.我可以生成迁移和快照的唯一情况是我的上下文没有DbSets.

我已经尝试了.NET Core的预发行版和发行版,以及完全卸载.NET Core SDK(因为仍然安装了旧版本)和Visual Studio并重新安装它们.

我在Windows 10 Pro上使用Visual Studio Enterprise 2015.3,我的模型类如下:

public class Player
{
    [Key]
    public int PlayerID { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我的背景如下:

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

    }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {

    }

    public virtual DbSet<Player> Players { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

和我的服务配置:

services.AddEntityFrameworkSqlServer().AddDbContext<LeagueContext>(config =>
        { …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework-core visual-studio-2015 asp.net-core

6
推荐指数
1
解决办法
3751
查看次数

捕获给定类型以外的所有异常哪个更好:catch and rethrow或catch when?

如果我想捕获给定类型以外的所有异常,并且将那些特定类型重新抛出以在更高的上下文中捕获,那么这样做会更好:

try
{
    //Code that might throw an exception
}
//Catch exceptions to be handled in this context
catch (Exception ex) when (!IsExcludedException(ex))
{
    //Handle leftover exceptions
}
Run Code Online (Sandbox Code Playgroud)

或者这样做会更好:

try
{
    //Code that might throw an exception
}
catch (SpecificException)
{
    throw;
}
//Catch exceptions to be handled in this context
catch (Exception ex)
{
    //Handle leftover exceptions
}
Run Code Online (Sandbox Code Playgroud)

还是真的不重要吗?有没有更好的办法?

c# exception-handling exception

2
推荐指数
1
解决办法
3374
查看次数