Easiest way to debug Seed-method in EF Code-first migrations in Configuration.cs when running Update-Database

Sequence contains more than one element

This post describes the easiest way to debug the issues that may stop your Seed-method in Configuration.cs from going through. The solution here shows you, how you can get a little bit more information out of the process, without attaching the debugger (there’s another blog post for that!)


Entity Framework’s code-first migration’s are a beautiful and easy way of managing database schema changes and populating some preliminary data there. Personally I also sometimes use the method for adding some enrichment to data or or custom property values mapping that would otherwise require an additional/external console program.

Problem: running the Seed-method is by default undebuggable

Okay – so seeding data is cool. That’s fine and dandy, but debugging the issues in the function while running Update-Database is NOT so cool. You only get the stacktrace and exception message – and that’s pretty ugly.

Continue reading

Launching a new debugger instance from code in Visual Studio

Sequence contains more than one element

This post describes a quick solution to launching a new Visual Studio instance for debugging the code. Where I’ve found this exceptionally useful, has been in debugging code-first migration’s (one of the ways for database initialiation in .NET) Seed-method. It is by default undebuggable, as when you are running Update-Database you can’t really use a -debug switch or anything, and there’s really no way to launch the debugger. Hence the best you can do is using -verbose to get more information.

However, if you actually want to see what is happening in the code, here’s the solution.

Continue reading

Attaching the Visual Studio debugger to the right IIS worker process

Visual Studio's Attach to Process -dialog

Every now and then comes the time when you’d actually need to debug something, and then you’ll likely be using your Visual Studio to attach the debugger to one or more processes.

Using CKSDev to attach to all IIS worker processes (w3wp.exe), or if you don’t use CKSDev, just pressing ctrl+p and selecting the processes from the list, is often a good enough solution. However, sometimes that makes your dev box sluggish, or maybe catches exceptions from code you’re not wishing to debug at the time, and it’d be handier to just attach to the one process you actually need. But how to find out the right one? Chances are, you’ll be having 3-6 w3wp processes, and you can only deduce so much from the process id…


Continue reading