Visual Studio 2015 crashing each time I run Update-Database

ef-code-first ef-migrations entity-framework entity-framework-6 visual-studio-2015


Each time I run Update-Database from the package manager console, Visual Studio 2015 is crashing. It happens to be running my migrations Configuration.Seed method at the time. Any idea where I should look to find out what's going on?

9/3/2015 9:21:42 PM

Popular Answer

There is a non-trivial chance that the crash is caused by project's code and not the inner working of Visual Studio.

As suggested by m_david in a question linked by the OP, the first step is to add following code at the beginning of Seed()¹:

if (System.Diagnostics.Debugger.IsAttached == false)

This will cause a prompt² to appear that will ask whether to launch the debugger in a new instance of Visual Studio or another currently running one.

After that, the debugger's output will be logged to Debug output of that VS instance, and unhandled exceptions will be treated as break points - with highlighting the offending line of code, exception details and all that.

In my case, the crash was caused by a recursive set() operation in a member of one of the entities, which resulted in a StackOverflowException.

¹ Or your DbMigrationsConfiguration subclass's constructor, if the crash happens earlier. Or possibly some other place.

² So remember to comment that code out when you don't need it.

5/23/2017 12:17:30 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow