Wednesday, December 21, 2016

Using XSDs with the F# XML Type Provider

In my blog post yesterday I mentioned the usage of the F# XML Type Provider to easily parse and process XML files. However the file I wanted to process(a NuGet nuspec file) had a lot of optional parts meaning that I had to provide a lot of samples to guarantee that the Type Provider understands my XML structure correctly.

However on the NuGet GitHub site, I found an XSD file. Wouldn’t it be a lot easier if I could use an XSD file instead?

The XML Type Provider doesn’t support this out-of-the-box. Luckily someone created an FSharp.Data.Xsd package that augments the XML Type Provider with schema support.

The Schema parameter can be used (instead of Sample) to specify an XML schema. The value of the parameter can be either the name of a schema file or plain text:

Tuesday, December 20, 2016

Use multiple XML samples with F# XML Type Provider

I’m a big fan of the F# type providers. They make my life working with JSON, XML,… a lot easier and less error-prone.

Last week however I had a problem when parsing a .nuspec NuGet file. I used the following NuSpec file as the sample file:

In this sample, you see in the metadata tags that some dependencies are available. However when I tried to load another specfile without any dependencies the F# XML type provider complained that it couldn’t find any dependency elements inside the metadata tag.

So how can I tell the XML type provider that the dependencies are optional? One way to do this is extend the sample file with another metadata tag without dependencies and telling the XML type provider that a list of samples is provided(using  SampleIsList=true).

Monday, December 19, 2016


Last week a colleagued shared the following error message:

NHibernate.Hql.Ast.ANTLR.QuerySyntaxException: Exception of type 'Antlr.Runtime.NoViableAltException' was thrown.

The error happened in an ASP.NET Web API controller using the built-in OData functionality in combination with NHibernate. Further investigation showed that the problem occured when one of the following OData filters were used:

  • startswith
  • a combination of ‘and’ and/or ‘or’ conditions

Some query url examples that are causing trouble:

  • Products?$filter=startswith(ProductName,’ABC’)
  • Orders?$filter=year(OrderData eq 2016 and OrderType eq 'FastShipping'

NHibernate is unable to parse the expression tree generated by ASP.NET Web API. Luckily someone already created a solution for this problem;

Install the NuGet package and apply the attribute to your queryable Web API controller action:

[Queryable, FixOdataQuery]
public IQueryable<Product> Get()
    return ...;

Friday, December 16, 2016

Nice quote–How tests make the difference

If you have tests, you can refactor. If you don't, you can only rewrite. Tests are the best tool you have to fight technical debt.

Source unknown

Thursday, December 15, 2016

How to NOT keep your software engineers…

I see a lot of organisations struggle to keep good software engineers. Although they pay their engineers well they see their best people leave and they cannot figure out why?!

Here are some of the malfunctions I noticed:

  • Respect: Treat your software engineers as overgrown children that play around with “toys”. Don’t involve them in any kind of decision making but micro manage them instead.
  • Involvement: Keep your software engineers as far away from business as possible. It’s not their job to understand business problems, their job is writing code.Don’t involve them in any kind of the non-technical decision-making processess. Throw requirements over the wall to engineering and expect them to implement it.
  • Hardware and Tooling: Provide your software engineers with outdated systems with unsufficient resources(writing code cannot require a powerful machine, right?). Deny any tool that can improve productivity and makes the life of your engineers easier. 
  • Accountability: Measure your developers on the lines of code they write(more is better), the number of bugs they create(less is better) and make exactly one developer responsible for a specific piece of code(how can you blaim the right person if multiple people work on the same code base?). Even better provide financial benefits for your top code writers. In the end software engineering is all about writing code, right?
  • Silos: Create organizational silos where engineering, testing, deployment are separated as much as possible(remember the accountability rule).

Any other unhealthy behavior you noticed?

Wednesday, December 14, 2016 Generate a JSON schema from JSON

JSON is becoming more and more the new XML. So similar to XML Schema Definitions(XSD) we see schema definitions pop up for JSON data. One tool that can help you generate a schema definition is

From the website: is a tool that automatically generates JSON schema from JSON according to the IETF JSON Schema Internet Draft Version 4. JSON Schema will be automatically generated in three formats: editable, code view, and string.

Using this tool, you provide a valid JSON object, click Generate Schema and done!


The generated schema can be viewed, edited(temporarily disabled) and copied:


Tuesday, December 13, 2016

Visual Studio 2017–Client-side debugging in Chrome

For a long time, the Visual Studio debugger allowed to debug both backend .NET code and client-side JavaScript running in the browser. Unfortunately the only browser were this was supported was Internet Explorer.

With the upcoming release of Visual Studio 2017, this will finally change. From now on you can debug your JavaScript and TypeScript running in Chrome  from inside Visual Studio.

You only need to select Chrome as your browser inside Visual Studio, hit F5 and a debugger will be attached.


Great feature!Smile

More information:

Monday, December 12, 2016

error TS1147: Import declarations in a namespace cannot reference a module.

A colleague mailed me the following error message when using TypeScript and the ‘import’ syntax to load module:

error TS1147: Import declarations in a namespace cannot reference a module.

Here is the related code. The error was thrown on the import statement:

We found the solution quickly. After moving the ‘import’ statements outside the module, the error disappeared:

Friday, December 9, 2016

AWS Lambda adds support for C#

Yesterday I blogged about Azure Functions and how the Visual Studio tooling can make your life easier. But the guys at Amazon are not sleeping and I noticed that they added support for C# as well.

Note that the AWS Lambda functions in C# are using the .NET Core 1.0 runtime. Similar to Microsoft, you get full tooling support thanks to the AWS Toolkit for Visual Studio.

  • Install the AWS Toolkit for Visual Studio.
  • Open Visual Studio and create a new project. Choose the AWS Lambda Project template and click OK.


  • Next step is to select a Blueprint.
    • We choose the Simple S3 Function blueprint.


  • You get a new project containing the following files
    • aws-lambda-tools-defaults.json: . This file contains default values that the blueprint has set to help prepopulate some of the fields in the deployment wizard.
    • Function.cs: Inside this cs file you can add your own logic.
    • project.json: this is the default project.json for .NET core applications(will be replaced by a csproj file in the near future)


  • The SDK is accompagnied by dotnet CLI integration. Open a command prompt and type dotnet lambda. Unfortunately I couldn’t find a way to debug locally.


More information at

Thursday, December 8, 2016

Visual Studio Tools for Azure Functions

I blogged about Azure Functions before. It is one of the incarnations of FaaS(Functions as a Service), comparable to AWS Lambda on the Amazon Cloud stack. But Microsoft wouldn’t be Microsoft if they didn’t had plans to improve the development experience. And yes, now we have (a first preview of )Visual Studio Tools for Azure Functions.

After downloading the preview, you get the ability to create a function project in Visual Studio, run and test them locally and publish them to Azure.

  • Once you have the tools installed, you can open Visual Studio and choose the Azure Functions project template. Click OK.



  • Next step is to add one or more azure functions to our project. Right click on the project. Choose Add –> New Azure Function…


  • The New Azure Function window is loaded. Choose a template.
    • As a an example I take the HttpTrigger-Batch, specify a random name and click Create.



  • Let’s try the sample by hitting F5. The first time you try to run/debug an Azure function locally you get a confirmation prompt to download and install the Azure Functions CLI tools.





Wednesday, December 7, 2016

Thoughtworks Technology Radar: Angular 2

On regular intervals, the people from ThoughtWorks release a Technology Radar update. Through this radar they share their thoughts on the technology and trends that are coming and going.


On multiple levels(Techniques, Tools, Platforms, Languages & Frameworks) they share if you should adopt, try, assess or move away(hold) from a technology and/or trend.

In the november 2016 update I noticed something interesting in the Languages & Frameworks. Where 2015 was the year of Angular.js, I noticed that no Angular could be found in the Adopt/Trial/Assess section. Instead you could find web frameworks and libraries like Ember.js, React.js and even Aurelia.

AngularJS could be found in the ‘hold’ section:


I’m wondering why they didn’t mention anything about Angular 2…

Tuesday, December 6, 2016

TypeScript File index.d.ts is not a module

After publishing my blog post yesterday about type definition files I got a problem when I tried to do the same thing for Modernizr:


Visual Studio finds my @types files but complains that it is not a valid module. In fact this makes sense. When using the import syntax, Typescript is looking for a 'module' i.e. a commonjs, amd, systemjs or umd module. Modernizr is added to the global namespace and is not available as a module.

To get intellisense, I have to use the ///<reference path=””/> syntax


Monday, December 5, 2016

Getting Type declarations in TypeScript 2.0

TypeScript has the concept of Type Definition files to provide TypeScript metadata for libraries that are not written in TypeScript. These TypeScripts files are maintained by the community and available at the DefinitelyTyped repo on GitHub. Before TypeScript 2.0 these type definition files were published on NuGet(Microsofts own package manager). As the TypeScript community kept growing and people outside the Microsoft ecosystem started using it, Microsoft decided to switch to npm as the package source for all type definitions.

So starting from TypeScript 2.0 you require no tools apart from npm. Let’s try this!

  • Open a web application in Visual Studio
  • Right click on your project and choose Quick Install Package… from the context menu
    • Note: if you don’t have this option, go install the Package Installer extension first


  • The Quick Install Package window is loaded. Choose NPM from the list of package managers and specify the library for which you want to load type definition files using the @types/<library> syntax.


  • Click on Install. After the NPM package is downloaded and installed, you can find it inside the node_modules folder of your project:


  • To use the library inside your TypeScript files, import the module and you’ll see that Visual Studio will search(and hopefully find) the related type information:


More information at

Friday, December 2, 2016

Block access to a specific folder in your ASP.NET MVC website

One way to block access to a specific folder in your ASP.NET MVC website is by combining the <location> with an <authorization> section inside your web.config:

In fact this is not the best approach as it is possible that this configuration is not applied when the ASP.NET pipeline is not invoked.

A better approach is to block the access at the IIS level by using the following configuration inside your web.config:

Thursday, December 1, 2016

The CRAP cycle and how to break it…

Did you ever hear about the CRAP cycle, the Create/Repair/Abandon/rePlace cycle?

You build an application. Over time you accumulate some technical debt. The application becomes harder to maintain. Developers start avoiding and working around certain aspects of the code. Maintenance becomes more and more expensive. Developers complain. New features become harder and harder to write and cost more. Business complain. The application becomes too complex to maintain, we abandon it and start replacing it. Only this time “we are doing it right!”. And of course we make the same mistakes. And the loop starts again…


How can we break this circle? What can we do to avoid it? Or is it an unbreakable law of software?

I don’t think it has to be. The problem is that most of the time architecture, code quality and a common set of guidelines are only applied at the beginning of a project. Although most applications are built using an iterative approach, the time spent in guarding the quality of the project decreases over time. And when the project finally arrives in maintenance mode, no one cares. The budget is gone, so every fix should be done as cheap as possible…

One the reasons is that the best developers/architects are assigned to new projects and that the lesser gods need to maintain it. This is really unfortunate both for developers/architects that move on(because they cannot learn from their mistakes) and for the poor guys/girls that need to maintain the project(because they get little room for improvement).

When is the last time you had to maintain the code you wrote?

Wednesday, November 30, 2016

NIST is bringing some common sense to password policies

As a consultant I’m frequently confronted with strange password policies. Every company I visit has different password rules with different expiration windows and so on. Although a password manager helps me to keep my sanity, I have a hard time understanding some of the multipage password rules that customers are using.

But ok, if it makes our systems more secure, it’s a burden I’m willing to carry. Unfortunately there is enough research available that shows that most of these rules make no sense and doesn’t help to improve security at all…

So reading the following post( about NIST(the United States National Institute for Standards and Technology) and the new guidelines for password policies they published made me happy.

An extract of some of the rules:

  • A minimum of 8 characters.
  • Allow at least a maximum of 64 characters(I hate it when I cannot use passphrases)
  • No composition rules (again, I hate it when I cannot use passphrases)
  • No password hints
  • No knowledge-based authentication(questions that only you should know the answer, like your favorite color Confused smile)
  • No more password expiration without reason

Thank you NIST!

Tuesday, November 29, 2016

NUnit tests are really slow when using Microsoft.Owin.Testing TestServer

After introducing Microsoft.Owin.Testing TestServer in a Test project we noticed that our test execution time increased from a few milliseconds for all tests to multiple seconds for each individual test.

With the help of dotTrace I noticed that most time was spent inside Microsoft.Owin.Hosting.Tracing.DualWriter. This class is used by OWIN to write all OWIN related data to the console.


After removing the related tracelistener using the line of code below, I noticed that the test execution time returned back to normal:


Monday, November 28, 2016

Fun retrospectives

In my job as a consultant I visit a lot of development teams. Most of them are using a ‘Scrum-like’ approach meaning that the typical Scrum ceremony(Daily Standups, Sprint reviews, Retrospectives,…) are in place.

However I noticed that especially the Retrospective becomes boring after a while. To spice up your retrospectives and make them meaningfull again, I recommend having a look at . This site brings a lot of activies and ideas together for making agile retrospectives more engaging.


Part of the information is also available as an e-book at

Friday, November 25, 2016

ASP.NET Web API 2 Request Pipeline

I remember a time where ASP.NET WebForms was mainstream and ASP.NET MVC and Web API still had to be invented. To do a good a job as an ASP.NET WebForms developer you needed deep understanding of the ASP.NET WebForms page lifecycle. (I even got some related interview questions at the time).

These times have gone and now you should understand ASP.NET MVC and Web API both having their own lifecycle. Here is a great poster explaining the ASP.NET Web API Message Lifecycle:


And a similar one for ASP.NET MVC:


Must print material! Smile

Thursday, November 24, 2016

Xamarin Workbooks

I started experimenting with Xamarin Workbooks as a new(better) way to create my API documentation. Workbooks are an interactive combination of executable code snippets and markdown documentation.


Xamarin Workbooks is a cross platform tool both available for Windows and Mac. Download information is available here:

After installation, it is time to create your first workbook:

  • Open Xamarin Workbooks. The new C# workbook window is shown. You can choose between a Console iOS, Android or WPF app(at the moment of writing).
    • Xamarin Workbooks uses the concept of agents. Agents are responsible to inject and execute your code in a specific application type. This means there is a seperate agent for WPF, iOS, Android,…
  • Let’s start simple and choose Console.


  • You are welcomed by a blank workbook.


  • In the workbook you can add two types of cells, either an executable C# cell or a documentation cell. Click on the + or “ button to add a new cell.


  • In a C# cell you can enter your C# code. The workbook will provide code completion, syntax coloring, inline live-diagnostics, and multi-line statement support to optimize the editing experience.


  • To execute the code you can hit <enter>, click on the play button or press <control>+<return>.


  • In a Documentation cell you can enter any documentation including images. Formatting is done using the MarkDown format


Some annoyances I have at the moment:

  • I noticed that the editing experience isn’t bug free yet. I got some strange behavior.
  • I couldn’t find a way to include my own assemblies or use my own NuGet server.
  • Compilation is (too) slow.
  • No undo functionality(yet).

It will be interesting to see how this application evolves…

Wednesday, November 23, 2016

TFS Build vNext: Build artifacts are not cleaned up on UNC file share

A while ago, I got a message from one of my customers mentioning that their build servers were running out of disk space. As they had a lot of teams and projects and each of these projects had at least a CI, Nightly and Release build, the number of build artifacts was growing at a large pace. To keep this under control, we reconfigured the build retention policies for all our builds. I removed most of the old CI builds and we were good to go, at least that was what I thought…

One week later, they called me again saying that one of the build server was again running out of disk space. I double checked all the retention policies, they all looked OK. However there were 2 things that I noticed:

  • The builds that were consuming all the space were TFS vNext builds using the new task based system. XAML builds didn’t cause any trouble.
  • Although I specified in the Build retention policy to only keep the latest build, I noticed in the drop folder that all previous builds were still there.


On the Connect site I found an explanation:

 The retention policy only cleans up build artifacts that are saved inside source control(server drops). Build artifacts that are dropped to a file share are not removed.

On UserVoice I noticed that this issue should be solved in VSTS and the latest bits of TFS 2015.

From the release notes:


Time to rollout an update…

Tuesday, November 22, 2016

SQL Server Extension for VS Code

Yesterday I discovered the following great extension for VS Code: mssql.

From the marketplace:

An extension for developing Microsoft SQL Server, Azure SQL Database and SQL Data Warehouse everywhere with a rich set of functionalities, including:

  • Connect to Microsoft SQL Server, Azure SQL Database and SQL Data Warehouses.
  • Create and manage connection profiles and most recently used connections.
  • Write T-SQL script with IntelliSense, T-SQL snippets, syntax colorizations, T-SQL error validations and GO batch separator.
  • Execute the script.
  • View the result in a slick grid.
  • Save the result to json or csv file format and view in the editor.
  • Customizable extension options including command shortcuts and more.


  • To install it, open Visual Studio Code
  • Open the Extension tab by hitting ctrl-shift-x
  • On the Extension tab, search for ‘mssql’


  • Click on the Install button. After the installation has completed, click on the Reload button to activate the extension.


Connecting to SQL Server

  • Oa new text file (ctrl+n) and change the language mode to SQL by pressing ctrl+k,m and select SQL.


  • mssql commands and funtionalities are enabled in the SQL language mode in Visual Studio Code editor.


  • Create a new connection profile using command palette by pressing F1, type sqlman to run MS SQL: Manage Connection Profile command.


  • Select Create. Follow the steps and specify a server name, database name and authentication type.


  • The created connection profile is already selected. If you want to connect to another database, press F1 and type sqlcon to run MS SQL: Connnect command, then select a connection profile.


  • Write T-SQL script in the editor using IntelliSense and Snippets. Type sql in the editor to list T-SQL Snippets.


  • Execute T-SQL script or selection of statements in the script by pressing F1 and type sqlex to run MS SQL: Execute Query command. You can also use a shortcut (ctrl+shift+e).
  • View the T-SQL script execution results and messages in result view.


Monday, November 21, 2016

.NET Core SDK not found

I downloaded a sample project from Github to experiment with the new .NET Core.  However when I opened it, I was welcomed by the following error message:

“.NET Core SDK Not Found”


This is a known issue and can be solved by downloading the correct version of the .NET SDK:

.NET Core 1.0.1 SDK 1.0.0-preview2-003131 download links
.NET Core 1.0.0 SDK 1.0.0-preview2-003121 download links
.NET Core 1.0.0 RC2 SDK 1.0.0-preview1-002702 download links