Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2015 crashing each time I run Update-Database

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?

like image 217
jlavallet Avatar asked Oct 20 '22 03:10

jlavallet


1 Answers

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)
{
    System.Diagnostics.Debugger.Launch();
}

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.

like image 153
Dragomok Avatar answered Oct 21 '22 23:10

Dragomok