FsUnit and Visual Studio 2013 “Could not load file or assembly ‘FSharp.Core, Version=…”

If you have been developing software for a while, you should already realize how essential unit testing is for your project. However, for F# programmer, Visual Studio doesn’t come with F# Unit Test Project. As F# is one of CLI languages, you can either use C# Unit Test Project or use F# syntax to test your F# code instead.

However, if you want to test F# with F#, there are many F# testing tools and libraries that you can try. What I use is FsUnit which has well-known F# contributors like Daniel Mohl and Tomas Petricek.

You can easily grab the FsUnit by using NuGet (FsUnit comes with NUnit by default, but it also supports MbUnit, xUnit, and MsTest).

But when you create a F# project on Visual Studio 2013 and run the FsUnit tests for the first time, you might see this error message with red unit test:

“System.IO.FileLoadException : Could not load file or assembly ‘FSharp.Core, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)”


The easiest way to fix it is to add bindingRedirect to the configuration file (i.e., app.config or web.config).

        <assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="" newVersion="" />


And it should resolve your issue.


Happy coding!


Cool Visual Studio Extensions for F# developer

For F# developer who also has C# background, you might feel like Visual Studio F# editor is very primitive comparing to C# editor. You won’t have a way to collapse a function (or method in C#) or type (or class) like in C#. Using indentation to create code blocks does reduce noise from the code, but a lot of whitespaces can still be hard to read sometime. And of course we don’t have ReSharper for F# yet.

Here are C# and F# screenshots:



These two cool visual studio extensions, F# Outlining and F# Depth Colorizer, could give you a better experience. The F# Outlining extension allows you to collapse F# code blocks based on indentation level while the F# Depth Colorizer alter editor background color in each level of nesting.

Let’s see the same F# code after I install these two extensions.


What do you think? For me, it makes coding F# which is already pleasant language to code in Visual Studio better. If you don’t like the default colors, you could change them to this cool dark theme colors (I am a light theme guy :-), so I haven’t tried it yet myself)

If you have any F# extensions that you want to recommend, please let me know.

Happy F# coding!

NOTE: As of 11/18/2013, the F# Depth Colorizer in Visual Studio Gallery doesn’t support VS2013 yet. Fortunately, Brian McNamara who creates the extension has put the code in GitHub. So I just fork it and make it supports VS2013. I also put the VSIX installer here.

NOTE: 1/29/2014, our reader (Dennis) lets me know that the VSIX for 2013 doesn’t work with Dark theme. I guess the code in GitHub was an older version and didn’t support Dark theme out-of-the-box. Anyway, since the colors can be set via registry, you can download the file,  dark-FSharpDepthColorizer.reg, from the same place, and run it.

NOTE: 4/12/2014, Depth colorizer is included in the Visual F# Power Tools. So you can just install the F# Power Tools and enable the depth colorizer feature instead.


If you want to switch back to light theme, you just run the file, light-FSharpDepthColorizer.reg, to remove colors from registry. (Although I have tested the reg files, please always back up your registry just in case).

Create F# ViewModel for WinRT app

Last night I gave a talk about WinRT and Caliburn.Micro at the Nashville .NET User group meeting. Caliburn.Micro is a popular MVVM framework for XAML-based application like WPF, Silverlight, and Windows Phone.

In the talk, I mentioned about using F# in the model part of the sample WinRT app. And that got attention from couple of members from NashFP who also use F#. The discussion lead me to consider using F# for the ViewModel part, so I did some research and found that F# developers have written articles and samples about using F# in ViewModel for other XAML-based application like WPF and Silverlight already.

So I try building a sample WinRT app and use ViewModelBase and RelayCommand implementation from “F# Windows App (WPF, MVVM)” template created by a fellow Nashvillian, Daniel Mohl.

Here is some code for View (XAML), ViewModel, RelayCommand, ViewModelBase:

And here is a screenshot from the app:



As F# is one of CLI languages and works fine in any CLR, everything works perfectly on WinRT as well.

You can found a full solution here.

Happy coding!