• List.Add() Index Was Out Of Bounds Of The Array

    I've been working on some bulk processes lately, and this error popped up on occasion, which at first glance was quite confusing - but a quick search online taught me something which I completely overlooked: List<T> is not thread safe. So if you're using Parallel.For() like me or just using threads in general, if you don't want to handle synchronization yourself, consider using one of the … more

  • Slow Razor Views in MVC? Make Sure You're Not In Debug Mode

    A short and sweet tip for today - I was investigating a page which I thought had some performance issues. My initial assumption was the backend controller, but a combination of SQL Profiler and Glimpse (which is super great and easy to use) showed me that the real bottleneck was ViewResult.ExecuteResult(). While someone on the internet suggested it might be a bunch of Url.Actions() causing … more

  • A few things you need to know if you're taking the Caledonian Sleeper train...

    Over Easter, I took a quick impromptu holiday break from London to Edinburgh. Being a last minute sort of deal, most flights and train tickets were pretty expensive, but I managed to get a few seats on the sleeper train departing Euston around midnight and arriving in Scotland the following morning at around 7am. Sounds great right? Now that I've experienced the trip there (and back), a few … more

  • The Mystery Of Javascript getDate vs getMonth Values

    Have you wondered why in Javascript, getMonth() returns a number from 0 to 11, whilst getDate() returns a number from 1 to 31? It turns out this isn't a mistake or an oversight, but by design; while it doesn't explicitly say so in http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf (page 340), getMonth returns a 0-based integer so you can use it easily with an array of … more

  • Pro Tip: Getting the physical directory / path for your Azure Worker Role

    Here's a quick one - adding files to your Azure Worker Role is pretty simple, through Visual Studio - everything under Roles\[YourWorkerRole] is automatically packaged up and deployed to Azure (as described here). Adding files is easy - but what about accessing them? It turns out that this isn't too difficult too. Azure provides you with a "RoleRoot" environment variable that you can use both … more

  • Looking Into Azure Diagnostics Logs The Right Way

    Talking about the Azure Diagnostics Logs - these are the WADLogsTable you can set up to trace errors, info and warning messages, etc. as described here. Setting up the logging is one thing, but reading the logs to diagnose an issue is another, and it turns out I've been doing it wrong all this time. I was selecting the output of the logs based on the Timestamp column, but there's two things … more

  • Using Spatial Data Types / DBGeography In Azure Worker Role

    I'd recently built some stuff that runs in Azure on a Worker role that interacts with some Spatial Data from a SQL Database via EntityFramework; having tested it locally, everything worked great. However, when published to the actual Azure environment, none of the data was being returned and my code wasn't working as expected. It turns out that the reason behind this is that in Azure you're … more

  • Planning To Use DbGeography And Points In EF: The Correct Format

    Here's a really quick gotcha if you're planning to use Entity Framework and Spatial columns with the DbGeography class support. As you're probably aware, you can't instantiate DbGeography directly, but you use methods instead, eg: DbGeography.FromText(); This method takes in WKT / Well Known Text, which is apparently a standard. A standard that I can't seem to find the definitive documentation … more

  • SQL Server Management Studio Not Presenting "Restore" -> "Database" Dialog

    I normally use a lot of backup / restore in SSMS to bring copies of production databases locally to develop or analyze, and on occasion I'd notice that doing the usual Right Click - Tasks - Restore - Database... wouldn't bring up the dialog to continue. So it turns out that this dialog doesn't actually appear unless you've previously made a backup of the database, which isn't always the case for … more

  • Running A Prerender.io Instance Locally On Your Machine

    Prerender.io is (as the name suggests) a prerendering service to allow Javascript-heavy websites and SPAs to be crawled by search engines. Recently, I've had some weird rendering issues with the pages it was caching so I wanted to do a bit of debugging. It turns out you can actually run the Prerender server locally on node.js as it's all open sourced! All it takes is a few steps, as outlined here: … more

  • MSVCP100.dll / MSVCR100.dll Missing Errors After Upgrading To Windows 10

    So, the day has arrived, the promised Windows 10 seamless upgrade and install... ...which as it turns out is not exactly a pain free process, what with Cortana being super buggy and not particularly useful (compared to the phone version), drivers being installed and messed up, and this issue, where the Visual Studio C++ Redistributables have some kind of issue. Anyway, if you get complaints … more

  • Correctly Posting String Data To A WebAPI Controller

    Seems like a pretty simple scenario, right? So I got to work and wrote the following: [HttpPost] [Route("api/users/me/delete")] public HttpResponseMessage CoolMethod(string myData) { } However, when attempting to actually call into the controller, all I was getting back was 404/not found errors. Seems strange, right? The following worked without issue, though: [HttpPost] [Route("api/users/me/ … more

  • Creating Your Own Custom Angular Maxlength Directive For Readonly Restrictions

    Here's an example - you've got a field (eg, for customer comments) where you'd like to limit the maximum number of characters entered on the frontend. Pretty simple, you just throw on ng-maxlength, right? <textarea class="form-control msd-elastic" ng-model="comments" ng-maxlength="100" name="comments"></textarea> But now, you also want … more

  • MVC Pro-Tip: Anti-Forgery Cookie Token And Form Field Token Do Not Match

    Just a really quick thing for you to check - one of the users of a MVC admin system I administer complained that they were getting this error message, after a release: System.Web.Mvc.HttpAntiForgeryException: The anti-forgery cookie token and form field token do not match. It turns out they hadn't logged out and back in again since the release - as we are hosting the website on Azure, the … more

  • Adding Multiple Messages To An Azure Service Bus Queue

    I don't know if this is a very common scenario, but I wrote some code earlier in the week to add a bunch of messages to a Service Queue: QueueClient queueClient = GetQueue(); foreach(var item in myItems) { BrokeredMessage message = new BrokeredMessage(Guid.NewGuid().ToString()); queueClient.Send(item); } This works fine for 5 messages, but it's actually kind of slow for 2000 … more

  • MVC Pro Tip: Rendering A ViewResult As HTML String Output

    Perhaps you've tried this - creating a controller, getting the ViewResult and attempting to convert it to a HTML string (for example, my use case was for an email templating / generation system). It's not terribly difficult, but there are a few caveats - primarily, that when you just "new" up a Controller outside of the proper MVC lifecycle, it doesn't have a proper ControllerContext associated … more

  • MVC Model Binding: Complex Objects and Collections

    Also known as "Why is my ViewModel returning null values to my HttpPost action?" The answer is at the very bottom if you feel like skipping straight to it. Let's say for example you have the following ViewModel and classes: public class MyViewModel { public ComplexObject MyComplexObject { get; set; } public int Value { get; set; } public IEnumerable<ComplexObject> … more

  • Enabling CORS (Cross Origin Resource Sharing) For Your Microsoft Azure Storage (Blobs, etc)

    Just a quick post about enabling CORS access for your Azure storage resources - I found most of the instructions I needed on this very helpful blog post. There's a code snippet on how to add the CORS rule to a Blob Service, but for the lazy / efficient ones, here's a little complete console app you can run: using Microsoft.WindowsAzure.Storage; using Microsoft.WindowsAzure.Storage.Shared. … more

  • Why Is Url Not The Same As RawUrl On My HttpRequest (Adventures in prerender.io)

    Merry Christmas / Happy New Year! Now that the holiday break is unfortunately over, back into the swing of things and good old hard work. Working on implementing prerender.io using the rather old (but does-the-job) MVC HttpModule on GitHub; I got it to a stage where prerender.io was working for the home page but no other pages on the site. A bit of debugging later, I noticed that the Url had … more