Unable to attach remote debugger after Visual Studio 2015 Update 2

As the title states: I was unable to attach the remote debugger (for instance to an Azure Web App) after installing Visual Studio 2015 Update 2. I got an error with something about invalid memory access or something like that.

The solution is simple: install Remote Tools for Visual Studio 2015 Update 2. Go to the webite, pick your machine’s architecture (the x86 install won’t run on a x64 machine) and click download. After installing, you’re good to go!

Hope this helps.

PS: There’s a list of Related releases on the Visual Studio 2015 Update 2 page. Have a look, it’s helpful ;)

Exception with EF code first migrations

Just ran into an exception when running both update-database and add-migration in the Package Manager Console for an EF Code First project. The Exception read:

The type initializer for ‘System.Data.Entity.Migrations.DbMigrationsConfiguration`1’ threw an exception.

The cause? An invalid config file for the project I was trying to run the tools for. So: if you run into this exception, check your configs ;)

Error saving Galileo Wiring App in Visual Studio

'The operation could not be completed' error when saving Galileo Wiring AppLast week I received my Intel Galileo board (from windowsondevices.com) and I started playing with developing for it yesterday. I created a first test project, but it didn’t run. Visual Studio couldn’t find the Arduino header file, which was probably due to a missing NuGet package (the Galileo C++ SDK). I tried to save the project, because you need to before you can manage NuGet packages, but to no avail. Visual Studio served me a ‘The operation could not be completed’ error without any additional information.

imageA while ago I posted about some handy settings in Visual Studio like Zero-impact projects & Cutting/copying empty lines. Turns out that the Windows for IoT project template does some extra things upon creation. And with the ‘Save new projects when created’ checkbox unchecked, it’s not able to do that. Rendering the project unsaveable…


The solution

It’s as easy as it is ugly to have to do this: simply check the checkbox in ‘Save new projects when created’ before creating your Windows for IoT project. Then you’re good to go…!

Hope this helps

Getting Bootstrap to work on Windows Phone 8

There are a couple of websites I manage that use Twitter Bootstrap*. These websites are fully responsive and work well on all devices. Or actually, almost all devices. The wrapping of columns in a container on a Windows Phone doesn’t work the way you’d want it out of the box. Windows Phone interprets device-width as the actual resolution size. Other mobile browsers use what the manufacturer (or browser vendor) has decided is the optimal viewport width.

To fix this issue, follow these steps:

  1. Add this line to use –ms-viewport in your CSS file
        width: device-width;
  2. Add this line to the head tag of your HTML page (it’s probably already there since you’re using Bootstrap)
    <meta name="viewport" content="width=device-width, initial-scale=1" />
  3. Add this JavaScript function as the first script in the head tag (because of a timing issue it won’t work if it isn’t the first script)
    (function() {
        if ("-ms-user-select" in document.documentElement.style && 
            navigator.userAgent.match(/IEMobile\/10\.0/)) {
            var msViewportStyle = document.createElement("style");

I found this solution over at Matt Stow’s blog ‘Firewoiks’. You can find the original article here.

Hope this helps.

* The Bootstrap project is no longer under the Twitter brand.

Originally created by a designer and a developer at Twitter, Bootstrap has become one of the most popular front-end frameworks and open source projects in the world. – about Bootstrap

Error: The Path ‘path’ is already mapped in workspace ‘workspace’

Just a quick little post today: I got the error “The Path ‘path’ is already mapped in workspace ‘workspace'” when I connected to a new Team Foundation Server and tried to map my workspace today. I had connected to a Team Foundation Services project a while back to get some shared code, but I already removed the workspace and the server binding. Even though Visual Studio didn’t see any other bindings, mapping my workspace to the same folder the previous TFS binding was mapped to served me this error.

The quick solution: manually edit (or remove if you don’t have any other bindings) the file VersionControl.config, which can be found under %AppData%LocalMicrosoftTeam Foundation4.0Cache

Hope this helps.

Visual Studio 2012 crashes when opening an ASP.NET MVC project with a cshtml open

vscrash A rather long title for this post, but that’s exactly what happened: when I opened an ASP.NET MVC 4 project with a cshtml view open, Visual Studio would crash with the error messages seen on the right. This would only occur if the first project I opened had a cshtml file open. When I opened another (type of) project first and then opened a project with a cshtml file open, the problem did not occur. Debugging Visual Studio with a new instance of Visual Studio (Inception anyone?) made things a bit clearer. (Part of) the exception information:


Could not load type ‘Microsoft.Less.Core.LessMixinDeclaration’ from assembly ‘Microsoft.VisualStudio.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’.

After searching around a bit, I found this blog post by Mads Kristensen: Web Tools 2012.2 and Web Essentials. This post talks about Web Tools 2012.2 and Web Essentials 2.5, and how an error can occur if you install Web Tools 2012.2 and don’t upgrade to Web Essentials 2.5. However, I do have Web Essentials 2.5.1 installed so this issue shouldn’t be the same as mine.

Although my situation didn’t match the one on Mads’s blog, I decided to install Web Tools 2012.2 just to see what the result would be. As it turned out, installing the Web Tools 2012.2 did solve the problem. Here’s why I think this solved it:

I had an older version of WebEssentials installed, which included specific functionality. This functionality was moved to Web Tools, and out of the new version of Web Essentials. When I updated to the new version of Web Essentials (without having Web Tools installed!), the functionality was no longer available in Web Essentials giving me the ‘Could not load type’ exception.
I’m not sure why the exception did not occur when I opened a different project first or if this is the exact reason of the exception occurring. I’ll contact Mads to share my findings, he might be able to reproduce this.

Hope this helps

How to add Next and Previous buttons to Twitter Bootstrap tabs

Just a quickie today: when working with Twitter Bootstrap tabs, like I am in my ASP.NET MVC 4 project, you might want to add Next and Previous buttons on the tabs to create something of a Wizard. Here’sa step by step overview of how I did this:

Add an ID to all the ListItem elements that are used for the tab navigation. For instance:

<ul class="nav nav-tabs" id="myTab">
    <li><a href="#example" data-toggle="tab" id="xmpl">Example</a></li>

Add a button you would like to use to activate the Example tab

In the onclick, call the ShowTab JavaScript function with the id of the ListItem for the Example tab (which is ‘xmpl’ in this example)

The ShowTab function is simple:

function ShowTab(tabname) { 
    $('#' + tabname).tab('show'); 

Hope this helps

How To: Call a generic method with a runtime type

Developing a generic class that maps datasets, datatables and datarows from a legacy system to my domain model, I ran into an issue. I wanted to call a generic method with a runtime type. Lets say the method looked like this: public string DoSomething<T>(string param). Because I use reflection to iterate properties on a type, the type of the properties was dynamic and only known at runtime. I wanted to do something like this:


This however resulted in an error message. The tooltip on the red colored propertyInfo read “Cannot resolve symbol ‘propertyInfo'”, while the build error stated “The type or namespace name ‘propertyInfo’ could not be found (are you missing a using directive or an assembly reference?)”. This is expected behavior, because “The type argument […] can be any type recognized by the compiler.” So that says compiler. So the type is parsed (and should be known) at compile time.

The solution is found in reflection. Taken from the MSDN article for the MethodInfo.MakeGenericMethod Mehod:
The MakeGenericMethod method allows you to write code that assigns specific types to the type parameters of a generic method definition, thus creating a MethodInfo object that represents a particular constructed method. If the ContainsGenericParameters property of this MethodInfo object returns true, you can use it to invoke the method or to create a delegate to invoke the method.

In our example, this would look something like this:

       .Invoke(mapper, new object[] { "bloggingabout" });

More information:
Generic Type Parameters (C# Programming Guide)
MethodInfo.MakeGenericMethod Method

How To: Create an ActionLink with a Twitter Bootstrap icon in MVC4

Twitter Bootstrap is a… “Sleek, intuitive, and powerful front-end framework for faster and easier web development.” One of the nice things in Bootstrap is you can use icons from Glyphicons. To use these, you can simply use this markup <i class=”icon-fire”></i> get a nice fire icon (fire ).
Translating this into an ActionLink styled as a button in an MVC4 application would look something like the following:

@Html.ActionLink("<i class="icon-fire"></i> Invent fire", "fire", new { @class = "btn" })

Unfortunately, this renders as follows:


The reason this is not rendered correctly is because Html.ActionLink HtmlEncodes the text you pass in the actionLink parameter. You can check this by opening the System.Web.Mvc assembly in your disassembler of choice, and having a look at the GenerateLinkInternal method on the HtmlHelper class. It HtmlEncodes the linkText, and doesn’t have any option to have it not do that. To solve this, I wrote an extension method called NoEncodeActionLink, looking like this:

public static IHtmlString NoEncodeActionLink(this HtmlHelper htmlHelper, string linkText, string action, object htmlAttributes) 
    TagBuilder builder; 
    UrlHelper urlHelper; 
    urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext); 
    builder = new TagBuilder("a"); 
    builder.InnerHtml = linkText; 
    builder.Attributes["href"] = urlHelper.Action(action); 
    builder.MergeAttributes(new RouteValueDictionary(htmlAttributes)); 
    return MvcHtmlString.Create(builder.ToString());

Calling the new overload (don’t forget to add a using statement to the namespace holding the extension method), the linkText parameter is not HtmlEncoded, which means the ActionLink now renders fine, including the icon (and the button style):


Hope this helps.

TIP: “Paste XML as Classes” in Visual Studio 2012


In the past, when you had some XML document that you wanted to translate into classes we had to create / generate a schema based on the XML file. Next, we had to generate a class based on the schema with an external tool. Not all too user friendly and somewhat time consuming.

In Visual Studio 2012 you copy the XML you want to create a class/classes for, place the cursor in a class file on the location you want the code to be added and select the following menu items: Edit – Paste Special – Paste XML as Classes. And you’re done! Just like that…

If you want to try real quick, there’s a sample XML file (books.xml) available here.

The feature is .NET Framework 4.5 specific. Taken from this MSDN article ‘Generating Data Type Classes from XML‘:
“.NET Framework 4.5 includes a new feature to generate data type classes from XML.