Stackify Prefix - first thoughts

Listening to one of my favorite podcast (.Net Rocks) I heard a plug for the Stackify Prefix tool which claims to help the developer fix problems before anyone else sees them - a bold claim. Well as I am currently working on a greenfield development project I decided to give is a whirl - it's free after all so why not.

Now I was not expecting to find too much wrong with the application and thankfully I was right - but I was getting errors.

The highlighted call is to a WebAPI method from an AngularJS controller (a JavaScript file on the client) and as you can see from the right hand pane it does succeed. In fact the data is returned as I'd expect and the application works without any issue. So why is Prefix flagging this?

Well, looking at the stack trace a little more carefully I see that the exception is being raised by the XmlMediaTypeFormatter when it is creating it's default serializer. But the WebAPI is returning JSON so why it is spinning up an XML serialiser?

Well, my WebAPI endpoint took this form:

The problem is on line 8 where I'm returning the OK status with the required content - which is an anonymous object that I've just put together on the fly. The WebAPI is configured to accept the 'application/json' header and to use an appropriate JSON Formatter - which it does. 

The problem is that I still have the default XML Formatter in the list and for some reason the framework is trying to use it to serialize my anonymous object - and failing (silently).

So all I need to do is to remove the Formatter during the WebAPI registration - within WebApiConfig.cs in the App_Start folder (see line 12 below).

Now this was fairly trivial but a bug is a bug and as we know - exceptions are expensive. They take time to raise while they pull the required information together and work their way through to the calling code - which in this instance appeared to simply discard it. A small performance hit but if this scaled then it could have become a bigger problem in the future - and probably harder to find.

Prefix highlighted it straight away and the issue is now fixed. It never made it to production, in fact it never made if off my desk - it was Pre-Fixed!


Why don't users "read the manual"?

In a previous post I had a little rant about some reviews I'd received from users of the FillLPG Android application. This was as a result of a handful of 1 star reviews from users who I believe had missed the point of the app.

You see, the application itself is just a portal into the FillLPG website - a website I do not control. The data provided by the website is maintained by a community of users who use the site and the app to add new stations, remove stations and update prices.

The problem is that users of the app have a place to sound off and express their displeasure - the Google Play Store. By leaving a 1 star review and the most basic of justifications for it (see previous rant) they get it off their chest and move on. 

Well, today I had another 1 star review but this time the user took the time to explain why he had done so, but in doing so showed that he had not 'read the manual' - or in this case, the app description.

I've not redacted the users name, he was happy to post this publically and thank Google that I only had 350 characters to respond!

The app has (at the time of writing) over 6000 active installations, it displays details of around 1000 stations every day and on average it is used to update 25 prices every day. Only 240 users have felt the need to rate the app and only 10% of those have left 1 star - and we know that people are more likely to complain about something than to praise it, so I'm not doing bad. But it does irritate me when people take the time to complain but don't take the time to read simple instructions. Even when you bring this to their attention they don't really bother taking it in or removing/updating their review, they just move on.

So what is to be done here? The app description clearly states that the data is maintained by the FillLPG community but obviously users are not reading this - or at least not all of it.

I could add a 'Getting Started' slideshow to the app which would be displayed after the initial installation - but we know that users just swipe or click next to get through these as quickly as possible without really reading the content.

Maybe users are their own worst enemy and we should just leave them to it - in this instance it is not as if I'm relying on income from the app, it's free and there are no ads, so if they uninstall it then I'm no worse off, in fact the contrary may be true!

Obviously I would like users to get the best from the fruits of my labours - but how do we (developers) do that?

Xamarin Certified Once More

I first passed my Xamarin Mobile Certification back in June 2014 but when it came to taking the recertification exam the following year I never quite got around to it. Ultimately it lapsed and I while I was no longer certified I did keep my University subscription running so that I could keep my skills up to date.

During the next year I have to say that I was quite disappointed as there didn't really seem to be any new content, i.e. no new courses were added as far as I could tell. At the end of that year I was considering not renewing my University subscription, at $1500 it was not exactly a no-brainer.

Then Xamarin was bought by Microsoft and it was included in the MSDN subscription, effectively saving me $2000. With the promise of new content I decided to renew my University subscription - I was $500 up anyway so why not I thought.

Well, as promised, new content is being added, a handful of Azure courses and one on Xamarin.Forms custom renderers so far. That and the fact that I'm currently engaged as a Xamarin developer I thought it would be prudent to refresh my certification. That, coupled with the fact that the Certification and Recertification exams are to change on 15th October this year meant I had a definite timeframe.

Xamarin list 10 courses as being required knowledge for the recertification exam so I spent a couple of weeks reviewing these - making notes and doing the exercises - before embarking on the exam.

The exam itself is 100 multiple choice questions which must be completed within three hours. The pass mark is 80% so not a lot of wiggle room here.

During the exam itself there were a few, shall we say, curve balls - questions which, to me, seemed quite ambiguous. One mentioned an image which was not present resulting in me having to guess the correct answer based on the text - which proved unsuccessful as it turned out - it was in the list of incorrect answers. If I'd missed the 80% by a single mark I don't think I would have been too happy. As it was I passed with a score of 87% which I'm pretty happy with.

Creating a Simple Modal Dialog Form for Xamarin.Forms

I’ve finally managed to get some time to look at the Smite Scoreboard application that I’m using as a vehicle to dive into Xamarin.Forms (XF) and it’s been a fraught time (see bottom of post).

Between incompatible nuget packages, mismatched Windows and iOS configurations and finding that XF didn’t actually support what I wanted to do I was pretty close to saying, “you know what, to hell with it – I’ll just use the native Xamarin approach instead”.

However, I recalled a video by John Sonmez titled ‘Why does Programming Suck?’ and rolled my sleeves up and dug in again.

Anyway – getting back to the Smite Scoreboard app and what is basically the first User Story.

As a user I want to be able to create a list of players, adding, editing and removing as appropriate.

Now, I know what I wanted to do to implement this story – a simple ListView with an ‘Add Player’ button which would open a modal dialog . The dialog would contain a ‘Player Name’ field with OK and Cancel buttons. Entering a name and tapping OK would add a new row to the ListView. Simple huh.

Well no, not really. While XF does support modal pages, which take up the whole screen, it does not support modal dialogs.

I tried a couple of approaches including the creation of a layout with an Entry field above the ListView which would replace the field I was going to put in the dialog. I had this partly implemented but really didn’t like how it was working and decided to bite the bullet and find a way or make a way!

And this is what I came up with (iPhone on the left, Android on the Right):

Yes – it’s not pretty but it shows me that I can do what I want to be able to do. Making it look nice is a job for later, lets get it working first 😉

So, on to the code. I decided to address the initial problem – how do I create a modal dialog (or the impression of a modal dialog) which will allow data entry? I didn’t worry about the ListView integration as I’m happy enough that I can make this work.

I found the key in Charles Petzolds book (which is free) and simply extended his solution to my needs.

Basically he uses an AbsoluteLayout which will hold the ‘normal’ page elements as well as a ContentView which will form an overlay that the user can see through but crucially not tap through. The ContentView is initially loaded with it’s IsVisible property set to false.

The skeleton xaml file looks like this:

  <!-- Normal Page Content -->
  <StackLayout AbsoluteLayout.LayoutBounds="0, 0, 1, 1"
      <!-- Normal Page Content -->
  <ContentView x:Name="overlay"
               AbsoluteLayout.LayoutBounds="0, 0, 1, 1"
               Padding="10, 0">
      <!-- Overlay -->

With this in place I added a button to the StackLayout and bound the Click event to a handler in the code behind which flipped the IsVisible property of the ContentView to True, thus displaying the overlay.

All I had to do now was to create a layout within the ContentView which looked something like a dialog. I came up with this:

<StackLayout Orientation="Vertical"
             Margin="0,20,0,0" >
  <Label BackgroundColor="Black"
         Text="Add a Player" />
  <Entry x:Name="EnteredName"
         Placeholder="Player Name"
         WidthRequest="250" />
  <StackLayout Orientation="Horizontal"
    <Button Text="Cancel" FontSize="Large"
    <Button Text="OK" FontSize="Large"
                  Clicked="OnOKButtonClicked" />

Wiring the buttons up to flip the IsVisible property of the overlay back to false and, in the case of the OK button, access the entered value was straightforward enough.

using System;
using Xamarin.Forms;
namespace SimpleOverlayForm
    public partial class Home : ContentPage
        public Home()
        void OnButtonClicked(object sender, EventArgs args)
            EnteredName.Text = string.Empty;
            overlay.IsVisible = true;
        void OnOKButtonClicked(object sender, EventArgs args)
            overlay.IsVisible = false;
                          string.Format("You entered {0}", EnteredName.Text), "OK");
        void OnCancelButtonClicked(object sender, EventArgs args)
            overlay.IsVisible = false;

The result may not be pretty right now but I think it will suffice for the time being until I can get to grips with theming etc.

The full source code can be downloaded from GitHub

It should be noted that I had issues when I attempted to update to the latest version of Xamarin.Forms via Nuget. The version installed with the ‘File > New Project’ did not seem to like the Overlay configuration and while the semi-transparent background was visible the ‘dialog’ controls were not. Only by updating from (installed by default) to (latest at time of writing) was I able to get this working. But it was not that simple (of course). Version has dependencies on specific version of the Xamarin.Android.Support packages, 23.3.0, but I’d already updated those packages to their latest versions ( This meant that I had to revert those updates and install 23.3.0 instead.

Unable to deploy Xamarin Android app to GenyMotion emulator

We all know that when you are developing mobile apps there is nothing better than running on an actual device. This is especially useful when wanting to access the device sensors such as GPS and the accelerometer. But we also all know that we have to test against a wider variety of devices than we have in our drawer. That's where emulators come in - and where the trouble starts in some cases, but I won't go into Hyper-V here!

Well I've been using GenyMotion for a little while and am very happy with it - to the point that I was about to put my hand in my pocket to buy a licence (which I may well still do). However, today I ran into a problem where Visual Studio would refuse to deploy to the emulator.

With the emulator running I selected it as the deployment target in Visual Studio and pressed F5, the build completed successfully and then, just before deployment the emulator disappeared from the list of targets and the deployment failed. I made sure I had the latest version of Genymotion installed (which I did) and that everything else was up to date (which it was).

While I was badgering Xamarin in the forums and via the support email I thought to fire up the Android Debug Bridge (adb) command prompt from within Visual Studio to check what devices the Debug Bridge was actually connected to:

Well, there you have it - it's a problem with the adb versions ..... wait a minute, how many do I have?

My understanding was that I should only have one - the one that Visual Studio connects to so that it can access the Android devices & emulators. And (I think) I was right on that score - I should only have on running. So what's with the version clash?

As it happens, Genymotion also ships with a version of the Android Debug Bridge and as it turns out, right now that one and the one shipped with the Xamarin toolset are not the same version.

Comparing versions of adb.exe (from Genymotion and the Android SDK) I found that Genymotion was currently at version 1.0.32 while the Android SDK has 1.0.36.

So what to do?

I suppose I could copy the adb files from the Android SDK into the Genymotion installation - but that frankly smells a bit to me and as it turns out it's unnecessary.

It is possible, within Genymotion, to set which ADB instance to use for each individual emulator. Simply select the emulator instance and click Settings. Select the ADB tab, click 'Use Custom Android SDK Tools' and browse to the SDK location on your system.

Note that the SDK will be in a folder called 'Android' within C:\Program Files (x86) or C:\Users\<user>\AppData\Local

Setting this resolved my issues and I am once again enjoying the flexibility of Genymotion and will be buying a licence very shortly.







StructureMap and MVC5 - Resolving the resolution exception for IUserStore

I'm currently working on an MVC5 website which uses StructureMap for Inversion of Control operations. Everything was working fine but then I started to get exceptions when I ran the application and attempted to login (not sure if Update 3 was responsible for surfacing this problem but it certainly worked without any problems previously)

Now, clicking 'Continue' in Visual Studio (or pressing F5) allowed the application to continue with no further issues but I wanted to get to the bottom of this issue - I certainly didn't want this coming back at me when the site goes live.

Clicking on 'View Detail' I found the following error message which seemed surprisingly informative;

No default Instance is registered and cannot be automatically determined for type 'IUserStore<ApplicationUser>'
There is no configuration specified for IUserStore<ApplicationUser>
1.) new ApplicationUserManager(*Default of IUserStore<ApplicationUser>*)
2.) MyDiveLogs.ApplicationUserManager
3.) Instance of MyDiveLogs.ApplicationUserManager
4.) new AccountController(*Default of ApplicationUserManager*, *Default of ApplicationSignInManager*)
5.) MyDiveLogs.Controllers.AccountController
6.) Instance of MyDiveLogs.Controllers.AccountController
7.) Container.GetInstance(MyDiveLogs.Controllers.AccountController)

So - what does that mean?

Well, in a nutshell it means that StructureMap could not determine how to create a concrete instance of IUserStore, which is required to create an ApplicationManager instance which is in turn required to create the AccountController.

This is caused by StructureMap being 'greedy' and will attempt to use the constructor with the most parameters. In the case of the AccountController it will ignore the parameterless constructor and try to use the one that requires an ApplicationUserManager (the root of my issue) and an ApplicationSignInManager. 

Having trawled around the web trying to locate a resolution I've found a couple of options;

  • Tell StructureMap to use the parameterless constructor instead or
  • Tell StructureMap how to instantiate the instances correctly

The first option is a simple matter of adding an attribute to the AccountControllers parameterless constructor as below;

public AccountController()

This works fine and if you are worried about how the AccountController will function without being given an ApplicationUserManager and ApplicationSignInManager to use then fret not - take a look at its UserManager and SignInManager properties. The getter will perform a null check and create the appropriate instance as required.

Interestingly, this helps us with the second option for resolving this problem, i.e. telling StructureMap how to create the instances for us.

Locate the IoC.cs class (mine was in a folder called DependancyResolution in the main MVC project) and update the Initialize method as below (note that you may have to import some namespaces)

public static IContainer Initialize() {
    return new Container(c =>

        // ADD THESE LINES
        c.For<System.Data.Entity.DbContext>().Use(() => new ApplicationDbContext());
        c.For<Microsoft.Owin.Security.IAuthenticationManager>().Use(() => HttpContext.Current.GetOwinContext().Authentication);


And that's it - you should now be able to access Actions within the AccountController without this exception being thrown.



Xamarin for Visual Studio won't Update?

I've been developing with Xamarin for a few years now and most of the time I do so using Visual Studio. Now, as with most technologies, Xamarin is constantly evolving and therefore updates are pushed out fairly frequently - that's all good, we all like new stuff don't we?

Well, I've always had a problem whereby Visual Studio would prompt me to say that there was an update available and that I should 'Click Here to Update' - the only problem being that this doesn't actually do anything!

In the past I've simply opened up Xamarin Studio, checked for and installed updates and then reopened Visual Studio - simple it's a bit irritating.

Well with Xamarin now being part of Microsoft and after rebuilding my development workstation I find that Xamarin Studio is no longer installed with the rest of the Xamarin components when Visual Studio is installed. So how do I install the updates now?

Well, after posting that very question in the Xamarin Forums I was guided to the answer which seems so obvious now (that's sarcasm by the way). I simply needed to navigate to: Tools > Options > Xamarin > Other > Check Now

Don't know how I missed that ;-)

Anyway - the bug with the notification looks like it's fixed now but just in case I thought I'd post this here for the unwary.

Visual Studio 2015 - Package Installation Error [Failed to initialize the PowerShell host]

Well today I decided to start a new Xamarin.Forms project in Visual Studio 2015 but fell at the first hurdle - you would have thought File > New Project would be simpler than this really. 

After clicking through all the errors I tried to build the solution which failed as badly as I expected it to - only 28 errors but all pretty severe.

Opening the Package Manager Console resulted in another error which seemed to indicate that a file was missing (nuget.psm1) but it was present, accessible and appeared to be intact.

So what's the problem here? Well, it's not actually Xamarin.Forms at fault - if I open Visual Studio with no solution loaded and then open the Package Manager Console I get the same error. I checked for updates and compared all the version numbers against the installation on my laptop (which didn't have the same issue) and everything seemed in order.

Well after a look (and I mean, a lot!) of Googling I found a cure for the symptom but not for the root cause.

When you open Visual Studio 2015 an instance of the devenv.exe.config file is generated in the following location: C:\Users\<username>\AppData\Local\Microsoft\VisualStudio\14.0 with a nice comment header indicating that modifications were subject to being overwritten. Now that's a bit of a pain because only by editing that file can I get the workstation to open the Package Manager Console correctly and hence generate a Xamarin.Forms project.

Add the following within the assembly binding section of the config file:

    <assemblyIdentity name="System.Management.Automation" publicKeyToken="31bf3856ad364e35" />
    <publisherPolicy apply="no" />
  <assemblyIdentity name="Microsoft.PowerShell.Commands.Utility" publicKeyToken="31bf3856ad364e35" />
  <publisherPolicy apply="no" />
  <assemblyIdentity name="Microsoft.PowerShell.ConsoleHost" publicKeyToken="31bf3856ad364e35" />
  <publisherPolicy apply="no" />
  <assemblyIdentity name="Microsoft.PowerShell.Commands.Management" publicKeyToken="31bf3856ad364e35" />
  <publisherPolicy apply="no" />
  <assemblyIdentity name="Microsoft.PowerShell.Security" publicKeyToken="31bf3856ad364e35" />
  <publisherPolicy apply="no" />
  <assemblyIdentity name="Microsoft.PowerShell.Commands.Diagnostics" publicKeyToken="31bf3856ad364e35" />
  <publisherPolicy apply="no" />

Now, the laptop does not have those lines in it's version of the file and it runs just fine so why the workstation is choking I have no idea - this is a quick and (very) dirty fix at best. From time to time you may need to reedit the file but at least you will be able to continue working.

The thing is I plan to pave this workstation soon and perform a clean installation so I'm not really looking to spend a great deal more time trawling the internet to find which obscure setting is flipped the wrong way and is causing this issue.


Aggregator Sites - What's the Point??

I recently experienced and issue with one of my Xamarin apps and decided to post the problem on the Xamarin Forums. It's a little obscure but I'm hoping that someone, somewhere has experienced the same thing and can point me in the right direction.

Well, in my lunch-break today I decided to take another look and entered the most concise search term I could think of - and received only 6 results, sometimes a good sign, sometimes not.

In this case it was the latter, mainly because there was only, actually one result - a link to my post on the Xamarin Forum. So what were these other results?

Well, they all point to the same site - Help4Mobile, which claims to use;

a concept which minimizes the duplicated subjects and content

Ironically it appears to do this by scraping data from other sites (which sounds like duplication in my book).

In the screenshot you can see my original post at the top (which is good I suppose). The next one down is the same post, scraped and re-posted by the help4mobile site. Now I'm not sure what will happen if someone was to reply to that post - I certainly wouldn't know about it - so what's the point?

The remaining results are different posts (probably scraped from some unsuspecting 3rd party site somewhere) and are returned because the sidebar on those pages contains links to the scraped version of my original post.

Now I'm confused by this. What is the point of this site?

  • It has no Ads so can't be trying to get traffic to generate revenue.
  • The original poster will probably never know if anyone actually replies to their questions - because they didn't post it on help4mobile.

Basically all this site is, from what I can see, totally pointless.

Insights is dead, long live Insights

In my previous post I sang the praises of Xamarin Insights and explained how it enabled me to locate a bug with the FillLPG for Android application.

At that time Insights as in Preview Release and all Xamarin subscribers has free access to the service, many like myself building it into production applications. We all knew that the time would come when Xamarin would decide that the product was mature enough and take it out of preview and start charging for it. At the recent Evolve conference (which I was not fortunate enough to attend) it was confirmed that existing users would still have access to the service but that plans were still being worked out.

Well, the plans have been worked out and the pricing released - and the news is not great for users like myself. It was hoped that existing users would retain free access, albeit limited, to all aspects of the service - but this is not the case.

The free tier is 'limited' to the real-time issue/crash reporting area (as used in my previous post) with all other areas, what I will refer to as Analytics, only available to paid subscribers.

Now, here's the crux of the issue - the entry level subscription is $199/month. When I received the email I actually had to read it a few times to make sure I was not mistaken - surely they meant $199/year didn't they?

Well, no - they didn't. Xamarin have put a price tag on this service is just shy of $2400/year. Now I, and others, see that as a bit of a slap in the face from Xamarin - after all, my usage during the Preview phase has surely been helping with their development of the service. That said, I do still have access to the Issue/Crash reporting part of the service and while there are some limitations being placed on that (log retention etc) this is the area I was making the most use of anyway - so frankly I've not really lost much, especially seeing as the Analytics have been offline for sometime now.

Now, FillLPG for Android was using some of the Analytics aspects of the service - I was able to tell how many users had actually logged in and how many had used certain functions such as updating or confirming a station price. That was interesting and has now been lost - in Insights anyway.

In the midst of this maelstrom a number of fellow Xamarin developers have mentioned the Mobile Analytics offerings from Google and Amazon and how they can be incorporated into Xamarin applications. These services are essentially free so I will be investigating them both shortly and intend to post the results in the coming weeks.