Debugging the Seed() method – Entity Framework migrations

This one has been fun. I’ve had a couple of issues when attempting to seed the ASP.NET Identity database using Entity Framework Code First migrations.

You would normally run the migrations via the Package Manager Console when developing locally, but this has an unfortunate side-effect – you can’t debug in the normal manner. If you have problems with your Seed method not working, as I have, it makes it rather difficult to figure out. Additionally, Console.WriteLine(), Debug.WriteLine(), Trace.WriteLine() etc don’t output to the Package Manager Console.

The solution? Open another instance of Visual Studio and attach the debugger to the original instance. Sorted.

Azure Blob Storage – connection string issue

More fun with the Azure API, this time with blob storage. Azure blob storage allows you to store large amounts of binary files or data, accessible (in full CRUD fashion) via a REST API along with some provided libraries for various languages, including .NET.

Microsoft provide an Azure storage emulator that runs locally on your development machine, and I had a bit of trouble connecting to it. The particular error I was getting was generated by this line of code:

var storageAccount = CloudStorageAccount.Parse(storageConnectionString);

The error itself was:

"No valid combination of account information found."

It turned out that the connection string for my storage account was formatted incorrectly for local development, despite conflicting things I’d read online – all you need, in fact, is this!



Visual Studio – Add Controller dialog has empty Model Class and Data Context Class drop-downs

Update: I’ve just had a reoccurrence of the issue described below, and the steps I mention resolved it.

A very lengthy and precise title, but this one has been a bit of a pain in the arse. Google hasn’t helped much, so hopefully the next poor git who encounters this issue might stumble upon this post.

So, the problem is this – the ‘Add Controller’ dialog box in Visual Studio 2013 sometimes doesn’t populate he ‘Model Class’ and ‘Data Context Class’ dropdown boxes when you’re tried to add a new scaffolded controller to an MVC project.

Everything was working fine for me initially, and then it mysteriously stopped working. Googling seemed to suggest a simple rebuild of the project would do the trick (it didn’t).

It’s now working, and whilst I’m not sure it’s down to the fiddling I’ve down or just pure chance, here’s a list of the actions I took to attempt to resolve this very irritating problem:

– Unload the .csproj file
– Manually look through the .csproj for any dodgy references. I found VS had added to the web.config entry for no apparent reason. Everything else looked ok.
– Reload the the .csproj file
– Clean the solution
– Rebuild the solution

I’ll update if it breaks again and update the steps to resolve accordingly. I can’t seem to find any information that explains the datasource of that dialog – where it gets the model lists from.

Link to similar issue:

Azure – some thoughts

I’ve been building a site recently using ASP.NET MVC. I thought it would be a good opportunity to have a proper play around with Windows Azure, which is Microsoft’s cloud service – as I haven’t used it for anything more than trivial demos and the like.

It’s been slightly more of a pain in the backside than I’d hoped – which I’ll explain in more detail in a subsequent post, as some of the problems I’ve encountered were not easy to solve using Google.

Here are some high-level thoughts, though:

– Azure doesn’t allow you to put a spending cap in place for ‘normal’ accounts. Only special accounts (such as the free credits you get with an MSDN subscription) have an automatic spending cap of zero, so that you can ensure you don’t go over your free credits. This is stupid, and rules out Azure for smaller websites / businesses. Any type of DOS attack or other types of non-legitimate / non-revenue generating traffic could end up with you footing a massive bill with little to no warning.

– You can deploy to Azure directly from Visual Studio 2013. It’s really easy to do and works quite nicely!

– Azure’s web interface is slightly over-complicated but it offers a lot of flexibility in terms of scaling / pricing.

– Multiple databases don’t transition that well from local development to Azure, unless you’ve got the appropriate incantations in place to make it work.