Friday, January 29, 2016

Angular 1.x to Angular 2 Quick Reference

A little bit short on time today. So I only want to share this great link that compares the syntax between Angular 1.x and Angular 2:

As I’m struggling a little bit with the new syntax, this is a great help when you couldn’t remember the exact code required.

You can always fallback to the official documentation, but this Quick Reference is a lot shorter and easier to use…

Wednesday, January 27, 2016

TFS 2013 XAML Builds: BuildDetail variable no longer available

After upgrading a customer from TFS 2012 to TFS 2013, we couldn’t access the BuildDetail property anymore inside our XAML build process template. Instead we got the following error message:

Error 102 Compiler error(s) encountered processing expression "BuildDetail.DropLocation".
'Microsoft.TeamFoundation.Build.Client.BuildDetail' is not accessible in this context because it is 'Friend'.

This is a breaking change when upgrading from TFS 2012 to TFS 2013. Luckily it is not hard to solve:

  • Open your XAML build process template
  • Add a Variable on the Variables tab
    • Choose IBuildDetail as type
    • Name it BuildDetail
  • Drag a GetBuildDetail activity inside your workflow
    • Set the Result property to the BuildDetail variable


Now you can access the same information as before…

Tuesday, January 26, 2016

Entity Framework Async: The source IQueryable doesn't implement IDbAsyncEnumerable<>

While investigating an Entity Framework issue, I stumbled over the following exception

The source IQueryable doesn't implement IDbAsyncEnumerable<VLM.PlattelandsLoket.Domain.Views.Codes.CodeValueView>. Only sources that implement IDbAsyncEnumerable can be used for Entity Framework asynchronous operations. For more details see


What’s causing this error?

Entity Framework 6 introduced async support through a set of extension methods. These extension methods are defined on IQueryable and IEnumerable but actually expect an IDbAsyncEnumerable implementation behind the scenes  to work. When you try to use one of these extension methods on a LINQ query that isn’t an Entity Framework query, you end up with the error message above.

I have to say I’m not a big fan of this approach, it sounds like a ‘leaky abstraction’ to me.

What do you think? Code smell or not?

Monday, January 25, 2016

.NET 4.5 Bug: Either ErrorMessageString or ErrorMessageResourceName must be set, but not both

When running an ASP.NET application on top of .NET 4.5, we encountered the following error:

Either ErrorMessageString or ErrorMessageResourceName must be set, but not both


The strange this was that we only noticed the issue on our test environment. On our local machine the application worked fine.

Luckily an explanation was found on the following blog:

It seems that this is a bug in .NET 4.5, as we had .NET 4.6 running on our local machine, it explained that we couldn’t reproduce the issue on our local dev machines.

As a workaround, you can follow the suggestion as mentioned in the post. Add an ‘ErrorMessage=null’ property to your Data Annotation:

Friday, January 22, 2016

MultipleActiveResultSets–what is it and should I use it?

On a project I had to review, I saw that one of the developers had enabled MultipleActiveResultSets(MARS) in the connection string. 

"Data Source=MSSQL1;Initial Catalog=AdventureWorks;Integrated Security=SSPI;MultipleActiveResultSets=True";

When I asked if he was aware that it was enabled and asked the reasoning behind it, the answer was a blank stare:


He just copied the connectionstring over from another project but had no idea why this setting was there.

MARS was introduced in SQL Server 2005 and enable the possibility to maintain multiple active statements in one connection. This enables the following possibilities:

  • Applications can have multiple default result sets open and can interleave reading from them.

  • Applications can execute other statements (for example, INSERT, UPDATE, DELETE, and stored procedure calls) while default result sets are open.

I see it most of the time in combination with Entity Framework when someone is using LINQ to iterate over a set of results and while iterating lazy loads related items. Most of the time, this is not a good idea as it indicates a N+1 problem that could be solved by materializing the parent collection or eager loading the related items.

More information:

Thursday, January 21, 2016

NuGet: Powershell script to set ‘Build Action’ property of files to ‘Content’

One of the nice things you can do with NuGet is to trigger a Powershell script (Install.ps1) when the NuGet package is installed or removed.

From the documentation:

A package can include PowerShell scripts that automatically run when the package is installed or removed. NuGet automatically runs scripts based on their file names using the following conventions:

  • Init.ps1 runs the first time a package is installed in a solution.
    • If the same package is installed into additional projects in the solution, the script is not run during those installations.
    • The script also runs every time the solution is opened (Package Manager Console window has to be open at the same for the script to run). For example, if you install a package, close Visual Studio, and then start Visual Studio and open the solution with Package Manager Console window, the Init.ps1 script runs again.
  • Install.ps1 runs when a package is installed in a project.
    • If the same package is installed in multiple projects in a solution, the script runs each time the package is installed.
    • The package must have files in the content or lib folder for Install.ps1 to run. Just having something in the tools folder will not kick this off.
    • If your package also has an init.ps1, install.ps1 runs after init.ps1.
    • [NuGet 3.x] This script will not be executed in projects managed by project.json
  • Uninstall.ps1 runs every time a package is uninstalled.
    • [NuGet 3.x] This script will not be executed in projects managed by project.json
  • These files should be located in the tools directory of your package.
  • At the top of your file, add this line: param($installPath, $toolsPath, $package, $project)
    • $installPath is the path to the folder where the package is installed
    • $toolsPath is the path to the tools directory in the folder where the package is installed
    • $package is a reference to the package object.
    • $project is a reference to the EnvDTE project object and represents the project the package is installed into. Note: This will be null in Init.ps1. In that case doesn't have a reference to a particular project because it runs at the solution level. The properties of this object are defined in the MSDN documentation.
  • When you are testing $project in the console while creating your scripts, you can set it to $project = Get-Project

Remark: Be aware that this no longer works in NuGet 3.x when you use the new project.json approach.

One of the things you can use it for is to interact with Visual Studio when a NuGet package is deployed. This makes it really powerful and allows you to do things like changing project settings, altering file properties,… For example, I have a NuGet package that includes some custom webfonts. When the package is installed the fonts should be included in the web project and the file property ‘Build Action’ should be set to ‘Content’. Here’s a script that allows you to do this:

Wednesday, January 20, 2016

TFS 2015 - Release Manager Workflow Migrator

The ALM rangers never sleep. Now they have created a Release Manager Workflow Migrator:

Looking to export a Release Management agent based deployment pipeline so that it can be reused in the Release Management service in Visual Studio Team Services (VSTS)?

We have released a migration tool and associated guidance as an open source project, allowing you to use “as is” or contribute to the project. If a Pull Request shows up at the door for the source or documentation, it will definitely be considered.

So if you are using Release Manager today and want to switch to the new Release Management service in VSTS, this will be a great help!

More information:

Tuesday, January 19, 2016

Goodbye Azure Storage Explorer. Welcome Microsoft Azure Storage Explorer

For years I’m a happy user of the free Azure Storage Explorer. It makes it really easy to work with Azure Storage Tables, Queues and Blobs.


Last week I discovered that Microsoft created their own tool with the original name ‘Microsoft Storage Explorer’. The list of features is not as large but it has one compelling advantage; it’s a cross-platform tool available for both Windows, Linux and Mac.

I’m certainly gonna give it a try…


Monday, January 18, 2016

Create your Azure Automation runbooks in a graphical way

Automation is a key piece in creating and maintaining your Azure environment. This month, Microsoft introduced a graphical tool and programming model to author and manage your automation scripts. So you don’t have to be a Powershell guru to start using the full power of Azure Automation.  Simply insert activities from the library to the canvas, link them together into a workflow, and configure the properties in order to create useful runbooks that automate your IT processes. 

Graphical Authoring Workspace

More information:

Friday, January 15, 2016

Embed fonts in your web page using Data URI

In web applications you can embed images into a html page by base64 encoding an image and add it to the css on your page by using Data URI. Data URI is just a URI scheme that provides a way to include data in-line. Usage is simple, you create an ASCII string format representation from your binary data using Base64 encoding. The generated string is then stored in the css. Instead of using an URI to an image, you use the Data URI instead. The format of this URI looks like this:

An example of an encoded image looks like this:

This is nothing new, but did you know that you can do the same thing for fonts?

Thursday, January 14, 2016

If you have too many dependencies it’s time for something else

I’m a big fan of the Inversion of Control(IoC) pattern and how Dependency Injection(DI) frameworks can help you implement this pattern.  IoC was really a gamechanger to me and had a lot of impact on the way I build and architect my applications.

Note: As I’m doing more and more functional programming, the need to use a DI framework is going away, but that’s something to discuss in another blog post

Unfortunately something I see a lot in applications that use a DI framework is something I call “dependencies diarrhoea”.

Let’s have a look at an example ASP.NET MVC controller to illustrate the problem:

So what’s the problem here? Without even looking at the full implementation, it should be clear that this class is violating the ‘Single Responsibility Principle’ and is doing too much in one class. This not only makes it harder to reason about this class, but also makes it a lot harder to test. There is no fun in mocking out lots of dependencies just to test a small piece of functionality.

One solution could be to use composition and create smaller components that do one thing and one thing well. This should already help to reduce the number of dependencies.


One disadvantage of using smaller components is that you sometimes end with large object hierarchies with a lot of coupling between these components. A solution for this could be the usage of the Publish/Subscribe pattern. You only focus on the dependencies that are directly related to the controller and for the other stuff you throw out an event that can be picked up by other components inside your system. This is a great way to further reduce the coupling inside your system.


Wednesday, January 13, 2016

Great Chrome extension–DOMListener

When building web applications using frameworks like Angular, React, and so on, there is always a lot of magic happening behind the scenes. This is all great until the moment it doesn’t work…

One tool that helped me a lot in investigating what’s going on inside the browser, is the DOMListener Chrome extension:

DOMListener is a simple tool that provides convenient interface for observing DOM changes (node removal and addition, attribute and text modifications). Events can be filtered with ease, affected nodes can be highlighted with a single click.


Tuesday, January 12, 2016

MSB4175: The task factory "CodeTaskFactory" could not be loaded from the assembly "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Build.Tasks.v12.0.dll".

After upgrading to TFS 2015, projects started failing to build on the (new) build server with the following error message: :

D:\Build\Sources\Source\App\.nuget\nuget.targets(71,9): error MSB4175: The task factory "CodeTaskFactory" could not be loaded from the assembly "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Build.Tasks.v12.0.dll". Could not load file or assembly 'file:///C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Build.Tasks.v12.0.dll' or one of its dependencies. The system cannot find the file specified.

We discovered that the issue was caused by the fact that we had configured a new build server with only Visual Studio 2013 and 2015 installed. On the old build server we had Visual Studio 2012 and 2013. As this project was created in VS 2012, it was looking for the Microsoft.Build.Tasks.v12.0.dll file in C:\Windows\Microsoft.NET\Framework64\v4.0.30319 folder. However in Visual Studio 2013 this file is no longer there. Instead you can find the file in  C:\Program Files (x86)\MSBuild\12.0.

To solve it, we copied the assembly from the new location to the Framework folder…

Monday, January 11, 2016

Using a TransactionScope with async/await

Maybe you didn’t know but the System.Transactions.TransactionScope object in .NET doesn’t play nice together with the async/await syntax. As long as all the code inside the TransactionScope is executed on the same thread, there is no issue. But when you start combining it with async/await you get into trouble. The following code doesn’t work in .NET 4.5:

Whenyou try to execute this code, it will fail with the following error:

System.InvalidOperationException : A TransactionScope must be disposed on the same thread that it was created.


A fix is available in .NET 4.5.1 but requires some code changes. There is a new enumeration TransactionScopeAsyncFlowOption that can be provided in the TransactionScope constructor. Here is the fixed code: