.NET Core: not your daddy’s dotnet

On March 29, we (my colleague Oscar van Tol and myself) held a 2.5 hour presentation about .NET Core at the Betabit office in Rotterdam. We ended up having too much content for the evening, so we decided to host a hands-on workshop for those interested, where we not only show .NET Core, but also enable you to have a go at it yourself. The location will most probably be Utrecht (because it’s located more central). Stay tuned for more info on the details of the workshop.

About that evening: we had a lot of fun doing this talk and we’re looking forward to doing more in the future. You can find the presentation on Slideshare, the sourcecode we used for the demos (and then some…!) can be found on GitHub: https://github.com/betabitnl/nyddn.

Happy coding.

Running Visual Studio as an administrator causes ‘Save changes to devenv.sln’ when double clicking solutions

After making sure my Visual Studio always ran as an administrator by following my own post HowTo: Have Visual Studio always run as administrator on Windows 8, I got a message if I wanted to save changes to devenv.sln each and every time I double clicked a Solution. Since the problem kept occuring after installing Visual Studio 2015 CTP6, I wanted to solve it. So here we go!

Double clicking a Solution file doesn’t start devenv.exe (which is set to be run as an administrator) but will cause the Microsoft Visual Studio Version Selector (VSLauncher.exe) to be run. This tool selects the right version of Visual Studio to open the Solution. Because VSLauncher.exe is not being run as an administrator, the error occurs.

The Solution

Find VSLauncher.exe, which is typically located at ‘C:\Program Files (x86)\Common Files\Microsoft Shared\MSEnv’ and make sure it runs as an administrator too. This will cause the Version Selector to be started with the correct privileges, helping it start devenv.exe with the right privileges. Problem solved ;)

Hope this helps

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.

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

Debugging JavaScript with Visual Studio in an ASP.NET MVC 4 application

When debugging JavaScript in an ASP.NET MVC (4) application, it is not always enough to uncheck the ‘Disable script debugging’ checkboxes under ‘Tools’ – ‘Internet Options’ – ‘Advanced’ – ‘Browsing’. JavaScript inside a Razor view (a cshtml file) cannot be debugged from Visual Studio. To debug your JavaScript, move it to a separate .js file and link to that file from your Razor view. This way, breakpoints set in the JavaScript will be hit and you can debug from Visual Studio.

Hope this helps


Disclaimer: I know about the F12 Developer Tools, Firebug and all the other possibilities we have to debug JavaScript. This post is about getting JavaScript debugging to work with Visual Studio and breakpoints set in Visual Studio. For those who want it that way. So there… ;)

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.

Unable to access the IIS metabase

The Web Application Project SomeWebProject is configured to use IIS.  Unable to access the IIS metabase. You do not have sufficient privilege to access IIS web sites on your machine.I opened a solution in Visual Studio 2012 on my laptop running Windows 8, when I was presented with the error “The Web Application Project SomeWebProject is configured to use IIS.  Unable to access the IIS metabase. You do not have sufficient privilege to access IIS web sites on your machine.” The user I was logged in with was a local administrator and was able to open up and use IIS Manager, but still I was presented with this error. The solution to this is simple: start your Visual Studio with ‘Run as Administrator’. You can do this by right clicking the shortcut and selecting ‘Run as Administrator’.

To always have your Visual Studio open with ‘Run as Administrator’, please follow these steps:
– right click the shortcut you are used to use
– bring up its properties
– click ‘Advanced…’ on the ‘Shortcut’ tab
– check the box ‘Run as administrator’ (see image below)
– close the windows with ‘OK’

Somehow I felt like this was default behavior on my Win7 VS2010 install, but it might be I set up the shortcut for it there too…

Ajax Control Toolkit Calendar doesn’t close when clicking outside the calendar

Just a quick one: if you have a textbox with a Calendar (extender) from the Ajax Control Toolkit and an associated PopupButtonID which is an image, the calendar won’t close when you click outside the popup. Use an input type=”image”or an ImageButton to solve this problem.

Hope this helps.