Understanding Span

C# 7.2 has introduced Span<T> along with a some language features so developers can better optimize code when using structs / value types.

To goal of this post is to (instead of explaining) present a collection of articles and blog posts that help the reader to fully understand these new features.

Let's start by the new features. The following article shall explain

  • in keyword

  • ref readonly

  • readonly struct

  • ref struct

Find out more


Custom VS Snippets

The 'copy-paste' task of developers has to be automatized. It is done by continuous improvement of languages, compilers, design patterns, libraries, packages, components, etc.

Having code templates is a bit of a different story. I have been using R# templates for a couple of years, and one can get really used to it.

Recently I have decided to plainly use Visual Studio, without the R#. One challenge I have is to move all my templates to VS snippets. I tend to use 6 snippets the most often:

  • Argument validation

  • Log informational message

  • Log error message

  • Create a test method

  • Create test setup method

  • Create test tear down method

Find out more


First look at SIMD in .Net

Recently I have been reading about Performance of .Net application, I ran into the following post explaining processor and cache affects on our code.

Processor pipelining shifted my interests to Single Instruction Multiple Data. SIMD has been added to the .Net ecosystem with the RyuJIT, as the following blog post details it.

There are a couple of mathematical and graphical use-cases described where this technology is applicable, but I still see a great opportunity ahead, where mass amount of real-time numerical data needs to be processed (and we are not willing to use GPU for instance). By curiosity I have created a couple of examples and compared the performance of these use-cases to regular code.

Note that the following examples use Vector<T> which is available through a NuGet package at the time. Only regular Vector2/3/4f are available in the full framework.

Find out more


Creating Certificates for Bot Framework apps hosted on Service Fabric

I decided to host a bot framework application over service fabric. Creating a regular Bot Framework app is relatively simple using the provided Visual Studio template and hosting in a free tier website service in Azure.

When using service fabric, even on a local test environment we will need to have a certificate for using external channels like Facebook, Skype or Cortana. This approach is also very useful if someone prefers to debug metadata on Facebook or Cortana messages, which is rather under-documented.

The certificate is needed for the https endpoint, in case an invalid (or expired) certificate the connection will not be established.

Once we have a domain name, we can use (as an example) Let's Encrypt to create the certificates for free. I used one of the suggested web tool: SSL For Free to generate the cert. The key step here is to use Chrome as the browser. At the time of the writing Edge generated invalid certificates. When the domain name is validated we will need to run the following command to generate a pfx file, so later we can install it into our cert store.

Find out more


Service Fabric - Https and Http

There are several good resources to set up Service Fabric Https endpoints. I would reference here HTTP & HTTPS in Service Fabric Web API which describes all the necessary steps to set up Http and Https endpoints. Doing the work manually will result pretty similar, except for the last step, which can trick the usual developer:

new ServiceInstanceListener(serviceContext =>
new OwinCommunicationListener(Startup.ConfigureApp, serviceContext, ServiceEventSource.Current, endpoint));

When you add one ServiceInstanceListener (Http or Https) the endpoint will open, but adding multiple, the code above will fail to open any endpoints.

The key step here is an optional parameter in the constructor of ServiceInstanceListener. Unless the name specified we will not be able to open multiple endpoints. So one suggestion to correct the above code:

Find out more