Making alexa skills in .net

Ok so I've been in the alexa skills market recently, and obviously amazon wants you to use AWS Lambda for your skills. If you are like me, you have a ton of stuff in azure app service (the PaaS of azure). Azure app service supports nodejs, java, python, and of course .net. The two sdk's amazon ships (node, java) do not tie in with a web stack, and are obviously thought of as being used with Lambda.

Continue Reading

Exploring the dotnet cli

Now that dotnet core tools have been released I thought it would be good to look into the dotnet cli. This is a new command line interface to build, manage, compile and run dotnet core based applications

Continue Reading

VS 2017, and dotnet core tools. Today will be a historic day

Today marks the release of Visual Studio 2017, and with it the final release of the tools for dotnet core. This means as of today you can build, test, and deploy an application completely supported by microsoft. Not just the runtimes, but the tooling as well. The CLI for dotnet core has been finalized, and its awesome. The csproj system has been revitalized. New csproj's can be created, and are fully compatible with the old. Visual studio 2017 has finally released. This is probably the greatest version of visual studio ever created. Finally VS has gone from a slow, archaic editor, to a fast moving IDE. An IDE with a DevOps-First Cloud-First mentality. An IDE ready to tackle today's modern challenges.

Continue Reading

StatsN a modern statsd client for dotnet core, and dotnet 4.5

tl;dr click here

When we talk about capturing metrics in applications. One server/service that constantly is in all conversations monitoring, is statsd. Incase you have never heard of it, statsd is a udp/tcp server that you send your in-code metrics to. These metrics get aggregated by statsd, and are forwarded to various backends. Some backends are services like librato or sumologic. Other times you are sending metrics to time series databases such as graphite or god forbid influxdb.

This boils down to in code you can say "log whenever this block of code is hit" or say "measure how long this function takes to execute". These stories come together to form pretty graphs, and rich alerts. All of this enabled by statsd.

Continue Reading

Parsing cli arguments in dotnet core Console App

tl;dr view this gist

So its 2016, and we are still making console apps/cli's. In fact I would say there has been a surge in popularity of these types of tools. I think we have come to the realization that buttons on forms are not automatable, and that the command line doesn't have to be scary.

I recently started writing an app in dotnet core, which is the new runtime for dotnet. In the past I have often used command line parser, but as of this writing it does not support core.

I was really lost trying to find an arguments parsing library when I realized the dotnet cli was open sourced.

After much struggle, failing to bingle. I started ripping through the Entity Framework, and dotnet cli's code hoping to find a gem. Thats when I stumbled across a diamond. You see many dotnet projects use Microsft.Extension.CommandLineUtils to do cli parsing.

Continue Reading

Bringin' turbolinks to .net

For a while now I have been playing with rails, and rack webapps. If you are not familiar with these, they are webservers created in ruby. One of the features I ran into during my journey into ruby land is Turbolinks. Incase you are not familiar, Turbolinks is basically a simplified pjax, with a lot of flexibility. When you click on a link in a page with turbolinks, the link action is hijacked and the target page is loaded via ajax. The result of the ajax call (which is presumed to be html) will replace the document of the body tag. At the end of the day its a technology to load your server side pages via ajax.

Continue Reading

Commiting a new file to git, through the github api

Recently I have been working on an application that basically has a github bot (aka user) fork a repo, commit some files, and submit a PR against someone's repo. When it came down to actually making a new git commit through the github API, I had quite a hard time. I figured it out with some help from a ruby tutorial, and now I'm going to show you how to do it.

Continue Reading

How the ASP.NET team made the web framework I have always wanted

So I know I do a lot of blogging about C#, or JavaScript, but I actually do a lot of nodejs apps as well as other languages. For a very long time I have not found the stack of my dreams. .NET has always been very close but there were multiple things about the app model that I was not a fan of. I think NancyFX has been the closest framework to my dreams in .NET land.

Continue Reading

Wiring up client side logs into c#/node.js logging frameworks

Around a year ago I joined a new team where I work, and this team was starting to undertake a full rewrite of their code. We were going from a full c#/mvc app to a tiny c# api, and a very big SPA.

Early one one of the huge things to do was to make sure that our JavaScript error logs could land in our Log4Net infrastructure. I started to write something to do just that, and as I was coding I quickly realized this was less trivial that it sounded. We had something internal we could use, but it was tied to a lot of other code that we didn't want to pull in.

I started Bingling around and I stumbled across jsnlog. JSN log lets you quickly wire up your client side logs to your server. I have been able to get PR's into the code base and the guy behind it has been very friendly to me when I have had questions.

Continue Reading

Moving from beta 7 to beta 8 in ASP.NET 5 (MVC 6)

So Beta 8 was recently announced, and I thought I'd update DotNetMashups to beta 8.

In case you havn't been paying attention, recently it was announced that helios was no longer a thing. Helios was the loader for ASP.NET 5 in IIS. Instead they are using the http Platform Handler to proxy the connections to kestrel.

So I thought that this was going to be a difficult update. I loaded the announcements repo in my browser and got to work. You can view the Pull request here.

Continue Reading

How .ToLookup() Saved me 4 hours a week, and got me some high praise from my boss

I recently created a small utility that is ran in jenkins to create indicies in ElasticSearch.

The first versions took around 5 hours to index our massive data into elasticsearch. This was still better than the 9 hours, our old solution took, so no one was complaining.

One of the major slowdowns was a .Where() on a List<T>. When I wrote the tool this TODO was written

//TODO: use some kind of key lookup here, but we need non-unique keys and Dictionaries are unique only

Continue Reading

Razor Websites, lightweight C# web coding

I was exploring around github, and I stumbled upon an interesting project called Miniblog which was a lightweight blog engine written in c#. The thing that immediately stood out to me was the lack of a .csproj file.

As I dug around the code I realized this was not a Web App, which most of us were familiar with, but a websites project. I then suddenly realized that the whole thing only used razor!

I am a huge fan of Nancyfx because its much more lightweight than the MVC framework created at Microsoft. To say the least I am a massive fan of small tools, and micro frameworks. So when I realized this whole thing was powered by razor only I was immediately impressed.

I decided to dig around on the internet to see if anyone else was talking about this. I found out quickly that it has been possible for some time, but I didn't find many references about it.

The one thing that bummed me out about the Miniblog example was that it was not a web app. You can use nuget packages will websites, but you cannot make references to other projects in the solution. This was a problem for me, and unlike websites, web app's are precompiled which reduces application startup time.

Continue Reading

Must Have Tool: NDepend

Code quality tooling has become a bigger, and bigger industry. Tools like Resharper, and stylecop have been telling us how bad us human beings are at developing code.

The one problem I have always had with these tools is they dont go above and beyond to help you understand your code at a higher level.

Continue Reading

Value types vs Reference Types in C#

In C# there are two kinds of types...Value and reference...

What are Reference Types?

Reference types in C# are mostly objects and strings. These are types when placed on a stack refer to a memory address in the heap.

What are Value Types?

Value types make up the bulk of types in c#. These include int, float, double, long, bool, etc. These types values are only stored in the stack.

Stack? Heap? What's the difference?

To put it short, the stack is a series of memory blocks (like a scratch pad) that is used for the current thread. The stack is used for basic property data access. Accessing the stack is very rapid, as its only used for trivial data. The heap is an area of memory for dynamic memory allocation. The heap is used to store things in data that are not value types, usually objects and strings. The heap is slower to access, but larger in size.

Reference type tripping points

Reference types are basically pointers. These pointers can trip you up in interesting ways. For example suppose you have an object called MyObjectName:

var MyObjectName = new SomeClass();

and you decide to make someone else's object name the same as you're name

var OtherObjectName = MyName;

When you change MyName to be something else, you will also change OtherName.

This is because objects are a reference type. On the stack the object is a pointer reference to the heap. When you make OtherName equal you are pointing it to the same memory address as MyName. You can see this in action here

var MyName = new SomeClass();
var OtherName = MyName;
MyName = MyName.Name = "Joe";
//OtherName will now equal Joe

This is also the same for array's if you make 1 array equal another, you will not have 2 array's with the same value. You will have 2 variables that point to the same array.

So the same must work for value types right?


If you have 2 ints and assign one int to equal the other. The value on the stack will be copied to that int, and since the stack value is the actual value they will be independent of each other.

Boxing and Un-Boxing

When you have a value type and you want it on the heap you must convert it to an object. This is called boxing

var val = 3;
var x = (object)val;

However once you do this, the two variables will be independent from each other. So if you change x you won't change val and vice-versa.

To get the object back on the stack you must cast it back into an int. This is called un-boxing

var y = (int)x;

Continue Reading

Custom error pages in Nancyfx (C# Web Framework)

To do custom error pages in Nancy you must implement an IStatusCodeHandler. This class must provide 2 methods. HandlesStatusCode is a bool that basically should tell Nancy if this class will handle the status code. If this returns true then this class will be responsible for handling the request.

Continue Reading

Abstracting Xamarin Android SharedPreferences

The standard way to get/set SharedPreferences in Xamarin is with the following code.

Get Preference:

 var shared = con.GetSharedPreferences(_preferenceName, FileCreationMode.WorldReadable);
 var value = shared.All.Where(x => x.Key == key).FirstOrDefault().Value;

Set Preference:

var shared = con.GetSharedPreferences("PreferenceName", FileCreationMode.WorldWriteable);
            var edit = shared.Edit();
            edit.PutString(key, val);

The main issue I have/had with this is you often have to know what will be returned, and what type you need to save as. Usually this isn't difficult, but it adds an un-needed level of complexity.

The other major issues I have with this, is that it is quite verbose, and unnecessary. The code duplication here can be quite high.

Continue Reading

Xamarin For Android The Conclusion: (Part 4 of 4)

Well verdict is in boys, and girls. Personally, I thought the platform needs to mature more. For those people who can pay for the business edition ($1000 USD/developer), and really prefer c#; then go for it. For most of us that can either do c# or Java; you may want to stick with Java.

C# vs. Java for Android

Essentially Xamarin is a competing product with using Java. I felt that the hefty price tag, and the lack of free support means the ROI for Xamarin will be low.

If Xamarin provided more in the way of automation tools, and documentation; it would be the clear winner

The fact is going straight to Java for most people is probably a must. Even if you are more comfortable with c#, finding help on the internet is much easier. As the platform matures, and more features are added hopefully things will change.

License cost deterrent

One of my biggest gripes with Xamarin is the very inflexible license schemes. You can get by with the $300 indie edition, but it is pretty clear they want people to go the $1000 business edition route.

The biggest deterrent to the Xamarin platform is the high cost of licensing.

With no sliding scale prices based on organization size, or project scope Xamarin is a tough sell (especially for open source projects).

Student Discount

Xamarin, does provide a student discount. They give 90% off for enterprise edition, and for those of you whom go to school this is almost a must buy. You could probably make it back with this simple formula.

Flappy bird-like animal + Mario pipes + admob = $$$


Personally I like Xamarin platform. The ability to re-use code for multiple mobile platforms can be helpful. For most of us tinkerers out there Android Studio is probably enough. For serious businesses, with a major focus on c#; Xamarin is probably the prefered method of development.

Room for improvement

Before I can fully back Xamarin I'd like to see better componants that provide more mobile platform abstraction, increased automation tools (visual studio macros could help here), and better documentation. From the activity of there web pages, I suspect all of these things are coming.

Continue Reading

Xamarin For Android The Ugly: (Part 3 of 4)

I had some problems with Xamarin. Somethings are ugly, but with plastic surgery almost anything can become beautiful.


Xamarin has its own software packages available for download. I tried a lot of them out, some were good others not so much. One of my biggest gripes was that Google Play Services currently has a bug that makes builds really slow. Other packages were either genius, or were simply unimpressive. The components have their own package manager, and it does do a decent job of keeping them in order. I have to admit though Xamarin has its own set of componants that do in-app billing, and access phone data without having to lift much of a finger.

Moving at the build speed of Play Services

Component Documentation

A real put down is that only some of the components have adequate documentation. For instance for me to get admob working with play services; I had to look at the Java documentation, and try to figure out how its supposed to be done on Xamarin. This wasn't to difficult, but admob is well used. I would have assumed the documentation would have covered it, but couldn't find anything.

Visual Studio Designer

The Visual studio designer for Android at first seemed like the best thing since sliced bread! I was able to get a UI up and running in no time. Making my app work for tablets, and mobile phones alike was simple. However, once in a while it would be stubborn, and stop working. I'm not sure if it was something I was doing, but I felt like it would bomb out and I would have to restore the XAML file to continue.

The editor really isn't great for designing ListViews, working with fragments, or making something that will scale easily. Often it made things exact pixel widths instead of using dots per inch. To keep it short, I still had to do plenty of editing of the source manually (which was not too bad). Making the theme stick on the default view was a pain, until I realized that I could ignore the editor, and decorate my MainActivity with the theme I wanted to use.

[Activity(Label = "Label", MainLauncher = true, Icon = "@drawable/Icon", Theme = "@android:style/Theme.Holo.Light")]
Continue Reading

Xamarin For Android The Bad: (Part 2 of 4)

Xamarin is a very good platform, but like everything it has parts that are not so great.


One thing that was really hard for me, was to find documentation that was newer than 2012. Android has made great strides with Ice Cream Sandwich, and Jelly Bean. New features such as fragments have breathed life into the platform.

The Xamarin documentation provides examples even with the newest features, but there is something about it that feels lacking. Almost like it was thrown together at the last minute. They have been doing webcasts to improve the knowledge out in the wild, but googling the answer to your problem just won't do. Part of the problem is that most developers write in Java, and only bigger companies can afford the hefty license fees that come with full support.

The user community was helpful at times, but I often found myself wandering though GitHub hoping my answer could be found in some mystical repo; Eventually having to study the full implementation to find the answer I needed.

Finding help

Although Xamarin has a forum where helpful users help each other, there are not nearly as many people coding on Xamarin than regular Java. Figuring out how to get something complicated working, was a nightmare. I'd look at a Java implementation, and then try to translate it into its Xamarin counterpart, which sometimes was far removed than the Java code. There are some examples of Xamarin for android out there, but nothing that really delves deep into manipulating the inner workings of the phone. I saw this especially when trying to edit contacts programatically. Xamarin support seemed helpful, but far too expensive for most freelance developers. This was a pretty huge put-off. If I went the Java route my questions would be answered with a simple search of stack overflow.


Like most things Java, Android requires a lot of boilerplate. For a developer like myself, whom avoids Java this was a problem. I would have thought that Xamarin would have abstracted out more of the boilerplate than they did. On the one had, having my code look somewhat familiar when I see Java examples was nice, but on the other hand because the API is still different often the Java versions would not be close enough to fully help. My main problem with this, is if I really wanted to write boilerplate I would have used the Java libraries myself. They did make a start for this by generating the manifest file automatically, but I feel it needs to go further to fully mature this platform as a viable alternative to Java.

Continue Reading

Xamarin For Android The Good: (Part 1 of 4)


This will be a series of blog entries where I discuss the Xamarin platform for Android.

I really enjoy C# programming language (JavaScript second)....Linq, Generics, anonymous methods, and Visual Studio are just some of the reasons I like it. Xamarin is a platform that gives you the ability you to write Android applications in c#.

When I heard about Xamarin I naturally, wanted to give it a shot. Having tried Eclipse, and Android Studio for android development I was no idiot when it came to the platform. So I got a license, and did nothing with it for six months, until a few weeks ago. After only 3 days I created Ultimate Gravatar Sync. An app that sync's your contacts gravatar images to their picture in your phone.

C# with no compromise

The Xamarin platform uses mono, and some kind of voodoo bindings to the Java libraries to make it work. I wont go in depth, but the native features of the C# language are there to use. I never felt like my hands had been tied, that all of a sudden I couldn't use a library that is normally part of the GAC (Global Assembly Cache). When I needed multi-threading, System.Threading was there, and when I needed to use C# Generics I had no issues implementing them.

Xamarin execution

Manage Android Manifest files

One of the things that blew me away about the platform, was that I never had to add anything to my manifest file. For those of you whom don't know, Android requires an XML config detailing the permissions you require, and the classes you have in your application.

Simple decoration such as:

[Activity(Label = "Label", MainLauncher = true, Icon = "@drawable/Icon")]

Will Generate in your manifest file as:

             android:name=".logoActivity" >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />

Adding permissions is also easy:

[assembly: UsesPermission(Android.Manifest.Permission.Internet)]

Using Java Libraries

Xamarin provides some kind of crazy visual studio project, that will essentially provide c# bindings to Java libraries you require. To bind Simply create a Java Binding project, adding the .Jar files, and then build. Watch the magic happen. They do note that you sometimes need to do some configuration for certain libraries, however I had no issues with the one I tried. On top of that if you really needed to, you could access the Java Native Interface for even more power.

Continue Reading