Automapper For Dummies

Today I was mentoring a younger dev, and he asked about how to handle data mapping between model and DTO classes. I advised him to use Automapper, which I find to be a quite simple solution for rather time consuming mapping task. I just couldn't find any decent guide for VB.NET & Automapper start-up, so I decided to write my own.

Add NuGet package

Right Click Project in Solution Explorer and select Managet NuGet packages...
Click Browse, type Automapper in search box, select it and click Install.


For this example I created two classes which are mapped: Person and PersonDTO

Then into fun part. First create instance of MapperConfiguration. This contains all the mappings that are used in this project. I could also use static Mapper.Initialize method, but I like the instance way more. 

MapperConfiguration takes in a method, so I have defined it as a lambda expression. CreateMap method calls defines a mapping between Person and PersonDTO. If I wanted to add some special rules for mapping, this method would be the right place to do it.

The actual mapping is simply done by calling Map method and telling mapper what type of data to take in.

And here's the result:

Using Automapper is very easy and I hope this VB.NET example is useful to get started with it.

The last few days of tinkering

I have been very busy with large system launch, so all my time has gone into writing SQL scripts, meetings and arranging things. This has affected my blog a little bit, but I'm trying to start writing new things again.

Redis and .NET things seems to interest people, so I will maybe wrap up latest changes from Redis and see how they affect .NET programs.

If you have any other wishes for new blog posts, give a comment below!

Exception Filters

I have been coding VB.NET for about seven years now and it still keeps surprising me with its features that are missing from C#. Today I stumbled upon exception filters.

Exception filters are way to restrict catch blocks with conditions.
        Catch ex As Exception When DateTime.Now.DayOfWeek = DayOfWeek.Monday
            MessageBox.Show("Exceptions are caught on mondays!")
        End Try
Exceptions filters are created with When -keyword and condition is specified after it.
This leads us to proper use case.

Catching multiple exceptions in one catch block

    Private Sub SomeMethod()
        Catch argException As ArgumentException
        Catch invalidCastException As InvalidCastException
        End Try
    End Sub

    Private Sub MethodThatWillCrash()
        Throw New ArgumentException()
    End Sub
This code will not show messagebox when code is run, because ArgumentException catch block is empty. We could fix it by changing the catch block to check exception type:
        Catch generalException As Exception
            If TypeOf generalException Is ArgumentException OrElse TypeOf generalException Is InvalidCastException Then
            End If
        End Try
But the Else statement is dull and catch statement is kind of unclear to read because it catches all exceptions.
        Catch generalException As Exception When _
            TypeOf generalException Is ArgumentException OrElse
            TypeOf generalException Is InvalidCastException
        End Try
With When -keyword we can specify types of exception to catch. Neat!

Exception filters posses great strengths, but beware, they can cause some unexpected behaviors:

Btw. exception filters are coming also to C# 6!

Top software developer podcasts

I spend around 40 minutes everyday at listening software development podcasts. They are great way to learn new technologies and easy way to keep track of latest trends. Currently I use the iPhone default podcast player and its good enough for me, on Windows Phone I used i Podcast alot and it was great also.

These are my favorite podcasts in a field of software development:

1. .NET Rocks

.NET rocks is a one of the longest running .NET podcasts. Episodes are well produced and there ain't too much of commercials in show. Guests are top of the line and hosts are doing good job asking interesting questions around the topic. Only minus is that hosts rarely challenge their guests to defend their opinion or to give a good argument why their 40302. Javascript framework is the best in the world. New shows appears more than once a week which is a nice thing for active listeners.

2. The Web platform podcast

Web platform podcast currently runs at 100. episode. Topics varies from Javascript frameworks into latest Microsoft Explorer version. Podcast has great hosts and topics are usually interesting and trending at the moment. New shows appears almost every week.

3. Javascript Jabber

Javascript Jabber is a well produced podcast which runs new episode once a week. Hosts have a good knowledge of web development (well maybe not Amy, but the others atleast!) and topics are usually well picked. Shows are quite ploated from commercials, but they are bearable.

4. Herding Code 

Herding Code topics are really interesting. For example latest episode (#217) guest was Nick Craver from StackExchange and he presented technologies and numbers behind the StackExchange. Bad thing about Herding Code is that they don't provide that many shows in a year. Currently there is only three shows released in 2016.
(Don't go to their web site, it's hacked).

5. Coding Blocks

My fifth choice is Coding Blocks. Coding Blocks is relatively new podcast (first show in 2013 and latest episode is 44.). Episodes are usually around two hours, so they are quite long compared to other software podcasts. Shows contains lot of chit-chat, so they could be easily fit into 1h, if you would pick-up only important parts. Topics are broad and there ain't any guests in shows which is refreshing.

Current state of .NET

In recent months Microsoft has announced dozens of new versions and names into it's development ecosystem. For a regular developer it's hard to keep track of all these announcements. That's why I made a short list of current state of .NET versions.


Latest .NET version is 4.6.1. Windows 10 has 4.6 pre-installed, and 4.6.1 after November update. There is a beta version of .NET 5 and its called .NET Core 5.


ASP.NET versioning is a mess. Latest ASP.NET version is a 4.6 which was released in July 20. There is a new version "5.0", which is in beta. ASP.NET 5.0 is also now called as ASP.NET CORE 1.0.

Check ASP.NET Core roadmap for more info about release date


Current ASP.NET MVC version is 5.2.3 and there is a release candidate for 6.0.  The MVC version consist the view-model-controller pattern implementation.


Current ASP.NET Web Api version is 2.2.

ASP.NET Core will simplify Web Api and MVC versioning by bringing them all under one version number.


C# is currently running at version 6.0 and there is a proposal for version 7.0.
Latest VB.NET version is called 14 and it was released along with Visual Studio 2015.

Table of versions

Product Current version Upcoming version
ASP.NET4.6Core 1.0
MVC5.2.36.0?/Core 1.0
Web API2.2 (5.2.3.)?/Core 1.0

Image from Business vector designed by Freepik

Seven cool things about the Visual Studio Code

#1 Command Palette

Command Palette is a new thing for Visual Studio users. It gives access to everything inside VSC. Command Palette is activated by pressing F1 and then typing desired keyword. There are few tricks to enpower Command Palette usage.
?  gives a list of available commands
: + line number  navigates to given line
!  shows errors and warnings
# + name  Open symbol by name.

#2 Extensions and built-in installer

There are quite nice amount of extensions available for VSC. There is an extension for Angular, C#, TypeScript and so on. Nice thing about these extensions is that you can install them directly from VSC by pressing F1 and typing "ext install".

#3 Intellisense

Visual Studio has very good intellisense, but so does VSC. It keeps suprising me all the time what it can do. It knows my json files, crawls through my code files and suggests me new things that I didn't know to exists.

#4 Open VSC easily from current folder

Visual Studio Code can be easily opened from current folder by typing "code ." Could it be simpler than that anymore?

code .

#5 Debugger

VSC has a debugger for Node.js (JS and TypeScript) and it's very easy to use. Just launch debugger, accept launch.json file creation and debug. If your main method is not in a file called app.js, change proper main filename into launch.json.

#6 Auto-update

Upgrading to the latest version is really easy. Approx once a month application will ask user to update. Clicking "Update Now", will download latest version, install it and restart app into latest build.

#7 Cross-platform

VSC is fully cross-platform and you can edit code from Mac, Linux or Windows. VSC doesn't restrict development machine anymore into one platform, which is a good thing in a long run.

Rider - Candy for .NET

Rider is new .NET IDE from Jetbrains. Jetbrains is the organization behind popular Visual Studio add-in ReSharper and Web IDE WebStorm, so own .NET IDE was kind of long waited product. .NET-community is used Visual Studio from dawn, but I think the time is ready for new IDE options also. Rider is currently in closed beta and can be optained only by invitation, but there is very good reason for that.

First launch

When Rider is launched first time it asks series of questions like "Do you want to use white or dark theme?" and "Do you want to use Visual Studio, Resharper or IntelJ key bindings". Settings can be changed later from File > Settings menu.

Main view

First impression

If I had to describe Rider UI with three words. Those would be: Menu, colorful and common. UI is more simpler than Visual Studio, however when first menu is opened from top menu, or when right click is used, the feeling changes quickly towards complexity of Visual Studio. Right click menus have lots of options and top menu is filled with tools and settings.

Visual Studio like menus
Default coloring differs from Visual Studio quite a bit. For example variables are colored in pink (in dark theme goddamn!) and method names are bright cyan. Very lively for dark theme. Coloring reminds me about the first appearance of Windows XP (oh the candy).

Lively and lovely

Feature rich

Rider has impressive amount of features, which mostly are familiar from Visual Studio.
For example actions can contain multiple key bindings, new items can be added simply by right clicking over folder and there are even VCS tools integrated into IDE.


Why there has to be always a but...
Rider is still in beta, which means that it still lacks critical features. For example there is no way to add references, debug .NET code (IIS/WPF/UWP) or run unit tests. These are features which must be implemented well, before Visual Studio can be overthrown from throne.

No summary support


Rider has lots of good features which makes it unique as it tries to stand-up from the shadows of Visual Studio. Like when folders are opened in solution tree, if the sub folders contains only one item, they are automatically opened. Rider also contains ReSharper features like "Find Symbol", which is now called Search Everywhere. Ctrl+Shit+Up/Down moves the whole code block up and down in logical level and so on.


Rider is not ready. It's not even close to ready, but it's on a good route! However there are black clouds hanging over its bright future. Visual Studio Code is surely bringing support for C#. One could say that Visual Studio Code doesn't have all the features that Rider has,  but then we step into Visual Studios territory. Rider has to find it's own place between Visual Studio and Visual Studio Code. That's not an easy task. Few key features in Rider may raise it into a new level, where it will be noticed. Features like good multi-monitor support and integrated CI tools (for TeamCity).

Project Rider web site