Xamarin – If I build it, will it run?

by BillKrat 8. March 2015 18:29

I may not know until the end of the year…. as I shared in my blog “Xamarin – from a seasoned Visual Studio developers perspective” without a ROI Xamarin won’t be on the budget until the end of the year.  However, this doesn’t mean that I can’t continue to create a framework that will be supported by Xamarin.  The way I plan to do this is to use an Xamarin Portable Class Library (PCL) in my Visual Studio project (ref figure 2) and put all of my shared code in it.

SOURCE CODE: Change set 107213

Xamarin Studio isn’t going to make it easy for me though, ideally it would be great if I could reference the MvpVmXamarinPcl project, create a Bootstrapper class in the TaskyAndroid project (more on this below), and watch it work with some basic functionality.   But this won’t be the case, as soon as a project references a PCL in Xamarin Studio – your greeted with a message that states it is not supported in the Starter edition.
So this leaves me with only one recourse – don’t make a reference to the PCL and periodically build the Xamarin solution to ensure it at least builds as I use/share it in my Visual Studio solution.  


Figure 1

I am very pleased to see that Xamarin supports Microsoft Unity IOC and MVVM Light!  This adventure went far smoother than I thought it would, particularly after the last adventure referred to in above blog link.

So I created a MvpVmXamarinPcl project in Xamarin Studio (it is a Portable Class Library, aka PCL) and added it to my Visual Studio solution for my open source password manager.  I then did the following:

  • Ported all of the code out of the existing Visual Studio PCL into the new MvpVmXamarinPcl
  • Used NuGet to install the MVVM Light and Unity packages
  • Deleted the now legacy VS PCL
  • Changed all my references to use the new Xamarin PCL project

and was pleasantly surprised to find everything compiled and the application successfully ran in Visual Studio using this Xamarin generated PCL project! 

What code am I placing in this Xamarin PCL?  An IOC framework, with event aggregation and classes emulating Prism libraries (reference image below); developers with Prism experience will feel right at home with this framework.   Thanks to MVVM Light I don’t have to worry about creating the XAML binding components.  Below in the left bottom corner of figure 2 I show the application running (with 5 modules).

Figure 2

Note: the only class from the above sequence diagram that is not within the framework PCL is the Bootstrapper class which resides in the primary application project.

The Bootstrapper (top left corner of image below) is responsible for loading the modules for the application.  In this case the modules reside in a separate MvpVmDesktop project (middle pane of figure below), each platform project will house its own UI components, for now I will be working on the Windows Desktop.

Currently, all of the modules are identical to the Menu Module in that there is only barebones code and each respective View (bottom left corner of image below) is data-bound to the same MainViewModel

Figure 3

As demonstrated below the only class from this point forward that will do any work (have code) is the Presenter, e.g., MenuBarPresenter (middle right pane of image above); neither the View or ViewModel will have any code that is not related to UI.  This is an important feature of MVP particularly for an environment such as this where each platform will have UI specific code sharing external logic; for the most part the MvpVmDesktop project will have only UI specific code, as will the MvpVmPhone, and later Android and IOS projects.


Xamarin – from a seasoned Visual Studio developers perspective

by BillKrat 1. March 2015 05:04

The minute my daughter was born I realized that TV sold a lot of hype on how babies look when they first come out; I stood there as a young 20 year old with my jaw dropped; she was all purple, yucky looking, and my first reaction was “put her back! she isn’t done yet”.  Well it turns out she was done and grew up to be a beautiful young girl and lady – so perhaps that is the moral to this story?
Day one with Xamarin was a wasted day of my life, I’m putting it back because it doesn’t feel like it is done yet, I’ll try again at the end of the year.   Perhaps I should have waited longer?  In my last correspondence with them a little over a week ago they indicated that in a couple of months they will release a “starter” edition that includes Visual Studio integration, but I should “dabble” in the current version until then.    This was in response to my request to have a version (like Microsoft Visual Studio) that would allow a developer to learn how to use their system without having to spend $900.00 up front (only Xamarin business edition supports Visual Studio integration); I indicated to them that there is no return on investment (ROI) and it is not in my budget.

A prerequisite for any Microsoft Visual Studio developer that wants to start dabbling in Xamarin is Jim Wilson’s webinar on “making cross-platform mobile apps with Xamarin and C#”.   This webcast goes a long way to answer a lot of questions that I had coming out of the gate in regards to the environment, although I must admit I only made it half way through because I was anxious to get started and my SamSung slate just reported a successful install of Xamarin.

The adventure follows:

My first mistake was downloading the following two applications off of the main page:


This is what kicked off most of my days efforts – I didn’t have an emulator so I couldn’t run anything.  


This adventure assumed a lot of knowledge on the part of the Microsoft developer, you have to know how to add an emulator.  When I first went into the Google Emulator Manager (from Tools menu) and created one it complained that there was not a CPU/ABI – some Bing research on this revealed that I had to add an image….


This eventually led me to the Android SDK Manager, between it and the Project Options (comparable to Project Properties for Visual Studio projects) I started to tie things together…

Xamarin Projects are tied to API versions on the options | Build | General tab.  The “Tasky” project that I was actually able to load and run in the emulator had two emulators “MonoFor…(API 10)” and “MonoFor…(API 12)” as shown in the bottom right pane of the image below.  In the case of Tasky project it was using Android 2.3 (Gingerbread).

So through a process of elimination I installed the Android 5.0.1 (API 21) images shown below (under status column) which allowed the Emulator to load.  I had to use the process of elimination because I only had 10 gig available on my SamSung slate (64 gig drive) and these images quickly consume gigabytes of drive space – first efforts failed after a very time consuming download process because it filled up my drive.


After hours worth of research, trial, error, and work I didn’t even get to see the emulator run….   I created a new Android 5.0.1 project, set the emulator and as you’ll see below a brand new project exceeds the “free” license size and I have to have indie edition or higher to use it… Indie is affordable but it doesn’t support Visual Studio and you can’t create Windows Phone applications in Xamarin (only VS) – so all of the constraints mean that only the Xamarin “Business” edition is feasible which has a $899 price tag which is not feasible without a ROI.


BUT I WASN’T READY TO GIVE UP – I wanted to see how it worked so I started browsing the code, I was curious how MVVM worked in this framework.   I started with the Login screen which had a ViewModel in a different project, I quickly saw that it uses the MVC/MVP Passive View pattern (see How it Works) in that the controller, LoginActivity class, is responsible for updating the view model; the view is not using the Observer Pattern (data binding).

I thought perhaps this would be different with a XAML view but when I added one the compiler complained and by this time I was done chasing issues so I simply deleted the XAML page.   BTW, it took me a long time to figure out that the Views are stored in the Resources\Layout folder with the code-behind (for a lack of a better word) residing in the root of the project.


BUT I STILL WASN’T READY TO GIVE UP, I wanted to see something run…  As I eluded to above I was able to load and run the Tasky project so I started dabbling with it – in all of its older version limitations….

So I loaded Tasky, was glad to see the emulators, clicked run and 3-1/2 minutes later the emulator was loaded and running the application.   No carpel tunnel problems here, plenty of time to rest/recoup.  I got curious and timed myself getting a cup of coffee from my Kuerig machine, making toast, putting the butter back in the fridge after buttering my toast and getting back to the office – walla!  3-1/2 minutes.  At least I can spend this time productively :)

But I was thinking, I can live with this for the ability to develop multi-platform….  So I loaded the view and was a wee bit disappointed in the available controls and design time experience.  Visual Studio WinForms and XAML really have us spoiled…   So I make a few updates to the screen, learned that I have to use a TableLayout (much like a Grid in XAML) and clicked run on the emulator.  It compiled and then …..


CRASH - the following was the only clue to the problem, the compiler was a happy camper and blindly handed the app off to the emulator.  The emulator didn’t like something….


It was becoming clear that you get what you pay for in the Android/IOS development world.  I trust that experienced developers in these environments would know what to do but as a newbie (experienced Microsoft) developer it is a miserable experience because we are use to having stuff just work.  If I add a project and hit run – it just works, doesn’t matter if it is Windows Phone, Tablet, Desktop, Web, or console.   The emulators rock!!

So I’m sticking a fork in it for now – we’ll see how far things progress.  I trust with Microsoft and Visual Studio in the scene we experienced Microsoft developers should be able to feel more at home and have things just work…

In closing…

You can emulate the development experience if you create a Portable Class Library (PCL) project in Visual Studio (which has no WinForms or XAML support) and put all of your shared code in it (this is all you can share); PCL is a subset of .NET which has less features than Silverlight does. 

The PCL concept is used for Xamarin development in that you create a Portable or Shared library for the code you will use between platforms, but all of your UI logic has to be done in the Android or IOS project (at least for Xamarin Studio).

Xamarin Studio does not support IOS for Windows, you have to use OSX (a Mac), likewise it does not support Windows Phone so it is pretty much useless unless you are doing Android development.

Visual Studio reportedly will support Android, IOS, as well as Windows Phone development, however after installing Xamarin successfully Visual Studio 2015 preview had no clue Xamarin was installed – so I was forced to play in Xamarin Studio.

It was truly an adventure….

I can guess your number in 6 steps (using linear algebra)

by billkrat 27. February 2015 03:50

I’m taking a linear algebra course and was tasked with an assignment to demonstrate how it can be used to perform a “magic trick”.   The instructor gave a couple of examples which got me thinking – “how can I use it to guess a persons number and reveal it to them”.  The answer follows:



How it works => CLICK HERE



Online 3D model editor and artist website

by billkrat 24. February 2015 19:12

Source: SculptFab-face.obj  (this is actually a text file)

The above source file can be loaded into SculptFab’s online editor at:https://labs.sketchfab.com/sculptfab/ 
Note: site worked with FireFox and IE 11.

Sculptfab is a very simple tool letting you sculpt 3D models in the browser and publish them in 1 click to sketchfab.com.   Tutorial is available at THIS LINK


I created an account at SchetchFab and with a click posted my 3D face to https://sketchfab.com/billkrat
Note: site worked with FireFox and IE 11.




The type name or alias … could not be resolved. Please check your configuration file and verify this type name

by billkrat 18. February 2015 08:38

This one took me more time than I care to admit as well as a number of dead-end Bing searches…   There are any number of reasons why Unity won’t load a configuration file, i.e., typo in “type” or “mapto” attributes, but in my case these were correct – I even copy/pasted both namespace and class names to ensure there was not some unforeseen typo.

What I didn’t quickly find was resolution to my issue which was that you must have an <assembly name=”” entry in your configuration file.  Once I added it Unity happily loaded the configuration file.


GhostDocUtil – adding custom pages to your .chm file

by BillKrat 16. February 2015 20:38

            Source: GhostDocUtil.zip (Visual Studio 2012 and greater)
  Prerequisites: Html Help Workshop  
                           When prompted associate .HHP file with C:\Program Files (x86)\HTML Help Workshop\HHW.EXE
Documentation: GhostDocUtil: Help folder contains a GhostDocUtil.chm file.   See Quick Start for more details

The Ghost Doc application is an amazing tool for documenting source code, I particularly like the preview feature.  The only issue I encountered was that it only generates an API listing, e.g., you’ll only see the area shown in the red box in figure 1. 

I found a way to back door the system so that I could add custom pages which prompted me to write a utility to automate the process.   GhostDoc generates all of the files necessary for the Html Help Workshop to compile a new .chm – thus providing the means to add custom pages.  However, after successful building the .chm it deletes all of the files (more specifically the temporary folder).  So the key was to figure out a way to prevent this from happening at a point when processing was completed.   The solution was to open the .chm after a successful build and then build the help file again, this generates an error message (which I ignore) which opens the door for GhostDocUtil to automagically generate the custom pages.

The entire process takes six manual steps which are outlined in the Quick Start page (see prerequisites above).  The important part is that you can author your custom pages using a normal .htm page as shown in figure 2. 

The GhostDocUtil.chm pages combined with the GhostDocUtil source code (which was used on itself to generate the documentation) should give you the information necessary to create custom pages for your project’s documentation

Figure 1 screenshot of .chm after processing custom pages

Figure 2 solution folder screenshot

GhostDoc solves the age old problem of documentation

by BillKrat 15. February 2015 10:02

See GhostDocUtil for information on how to create custom pages in your .chm.

Historically the problem with technical software documentation has been keeping the UML diagrams and/or documents in sync with the code.  GhostDoc Professional and Enterprise now offers a solution to the problem.

GhostDoc not only provides an easy means to generate XML documentation, it also supports the ability to easily add images and preview documentation.  In figure 2 below I show the UML sequence diagram that represents the business logic flow of the BootstrapperBase class.  In the future, if I am working on this section of code all I would have to do is right click on the code and request a preview (reference figure 1).  It will show me the documentation preview shown in figure 2 (right pane) where a picture will truly say a thousand words – particularly when I reference this diagram from the bootstrapper class that will derive from it.

As for up-keep, all I have to do is keep the XML documentation current as I modify the code and after updating the UML diagram I’ll then then capture a screenshot of it saving it using its use case designator, in this case SD0300-020-075-010.PNG.  Walla!  We’re documented and can move on without looking back; all references to this use case within documentation will be updated when I produce the .chm file.  Likewise it will be current for the next preview.

This provides a great return on investment making it worth the time to clearly document each process in a class. 

I will be using this for my open source project http://PasswordMgr.CodePlex.com which will utilize my Prism Light framework

Figure 1 right click on code, select GhostDoc Enterprise, and request a preview

Figure 2 code with preview

MVPVM - Overview

by billkrat 15. February 2015 05:04

Read article on MSDN

The MVC Presentation Model pattern was the development pattern that was used for early development, it is synonymous with MVVM. Some of the problems encountered with this pattern were ViewModel bloat, inability to reuse components, pollution of domain objects with view state, and no access to view components (as only data binding was used).

Because of these limitations our late architects evolved to the MVP (Model-View-Presenter) pattern - reference Martin Fowler article on GUI Architectures for more information.

John Gossman, father of MVVM, noted “On naming, my opinion at this point is the the Model-View-ViewModel pattern is a WPF-specific version of the PresentationModel pattern. PresentationModel is a lot easier to say and to write, and is more widely known...but for now I'm sticking to M-V-VM terminology in my own thinking in order to capture the WPF-ness and to avoid any interpretation conflicts”,

I refer to the WPF specific version of MVP as the Model-View-Presenter, ViewModel (MVPVM) pattern for the same reasons noted by John.


If In my experience I have found that developers are well aware of pattern rules, such as not having a View referenced from the ViewModel, but I found they lost track of the reason why; in case you are one of those developers, the reason is because it prevents reuse of the ViewModel; the ViewModel should be able to be accessed by multiple  views depending on your use case (more on this below). 

Reuse is the primary reasons we also have a rule that says we don't want to put code in the Views code-behind.  So we defeat the purpose of this rule if we put all of our code in the ViewModel because we essentially turn our ViewModel into a View’s code-behind without the benefit of being able to access the view components; worst yet, we cannot share it with other applications or platforms. 

The MVP pattern allows our developers (as a rule) to access the View and ViewModel equally, this permits the components to remain decoupled allowing them to be reused by other applications and platforms.  Some developers may feel that MVPVM is an enterprise development pattern not to be used with small programs, however I suspect most of us have experienced that small program that turned into a large application – they have a tendency to grow feet, suffer from scope creep (once client knows what they can have), and can become impossible for reuse  of components.

Many years ago I wrote a small application for the Amarillo Medical Group, it was for handheld device that was going to allow the doctors to track their billing.  After the first release some doctors wanted it on a laptop so I had to write a second program the worked on the desktop platform.  Later, some doctors wanted access from a website so the small program turned into three applications.  One day a doctor asked for a change to the application and couldn't understand why he was charged for three application updates - he felt it should have been a change in one place and this caused frustration since the apps looked exactly the same.  It was this experience that sent me down road looking for a way to develop one program that could be used for all platforms.  I started the journey on my open source project http://PasswordMgr.Codeplex.com.  Along the way I learned the importance of creating reusable, decoupled components and the value of MVPVM as MVP was a pattern created to achieve this goal; those who do not learn from the past are doomed to make the same mistakes.

In the PasswordMgrV3 folder of the Codeplex open source project http://PasswordMgr.Codeplex.com, we created an ASP.NET MVC application and pulled all of the login view models into a reusable portable class library.  This will permit us to create views that can reuse these view models from the desktop, tablet and phone platforms (as well as the Web platform).  So you can see that If we tie a view models business logic to one platform we won't be able to easily reuse it on the others.  So as MVPVM dictates we’ll move the business logic into the controller or presenter as applicable.   The goal is that the use cases in gray below can be reused cross-platform, on all devices, using one set of code written in C#.  For this purpose the Prism Light framework was born.


Prism (light) for Xamarin

by billkrat 14. February 2015 10:26

Prism Light

Source code: CodePlex 
Change set: 107164

I am excited about the technology that will permit us to develop cross platform applications; Xamarin provides the ability to program to IOS, Android, and Windows devices.  This is a band wagon I am ready to jump on and fortunately there is a toolkit that is paving the way to make this easier for us – the MVVM light toolkit.   Although I will be using MVPVM for my application framework design, I will be able to use the components of the toolkit to make this job easier.  

It was great to see that Unity is supported by the portable class library, I’ll use this instead of SimpleIoc but I didn't see any support for Prism just yet.  This will require me to roll my own until something is available,  unlike my efforts in the past (my PasswordMgrV2 folder has a Prism portable class library that I ported) I am going to take a more agile approach and only create the Prism “like” components that I require at each phase of development.  I’ll use the MVVM Light toolkit components where applicable, in lieu of creating a Prism “like” component.

The goal for the POC was to modify the MVVM Light template as little as possible while providing MVPVM capabilities.  The end result is shown below for this phase of development:


The above screenshots shows four modules (top pane).  A module is the equivalent to what you would get if you created a single MVVM Light template – a single view that represents a use case.  The four modules in this POC are the menu, status bar, user (left pane), and generator (right pane).  At this phase of development they all have the same module code shown above with different views containing the XAML shown below:

        <TextBlock FontSize="18"
                   Text="{Binding WelcomeTitle}"
                   TextWrapping="Wrap" />

The modules reside in a project called MvpVmDesktop while the MVPVM framework resides in project MvpVmPcl, it a portable class library that should port over to Xamarin, we’ll know more when the Visual Studio 2015 Starter license becomes available in a couple of months.

MVVM light developers will feel right at home when they open the POC project as all of the binding and wire-up is the same.  I made only the changes shown in red boxes (image below), the bootstrapper is the only new class. 

Prism developers should feel right at home with bootstrapper, EventAggregator, and module concepts.  I did implement my own ILogger (not Prism’s LoggerFacade) at this point so that I can subscribe to logger events – this allows me to easily send logging information to a textbox (coming soon).  This framework is barebones but functional as of this change set.

You’ll notice that in the solution there is a web project (MvpVmWeb).  This web project uses the MVC template, I removed the view models from it and moved them into the MvpVmPcl (portable class library project) so that I could use them in the log-in module of the MvpVmPoc (desktop app); reuse of views and view models is where MVPVM shines.

Since the ASP.NET MVC website uses these view models I would not want to add any business logic to them.  In MVPVM it is the each module’s presenter (coming soon) responsibility to populate the view models as required allowing the views and view models to remain completely decoupled.

Note: as this framework progresses there will be a Windows Phone, Tablet, Desktop, and Website password manager application that utilizes the same code and view models – only the UI code will be different.   When it comes time for IOS and Android, via Xamarin, I should only have to create those UIs as well.  NO CODE will reside in views and view models (outside of visual state and bootstrapping) making the transition to other C# supported platforms easy.


The temp directory in chart handler configuration is not accessible

by billkrat 21. January 2015 08:03

If you encounter this error you will need to add permission for IIS_IUSERS or if applicable NETWORK SERVICE to read, write, and modify.   To do this, select your web application folder under inetpub\wwwroot using the windows explorer and then right click on folder, select properties, security tab, edit button, select IIS_IUSERS or NETWORK SERVICE as applicable, and then click the modify and write checkboxes.

Excerpt from https://msdn.microsoft.com/en-us/library/ff647402.aspx follows:

File Access

The Network Service account has Read and Execute permissions on the IIS server root folder by default. The IIS server root folder is named Wwwroot. This means that an ASP.NET application deployed inside the root folder already has Read and Execute permissions to its application folders. However, if your ASP.NET application needs to use files or folders in other locations, you must specifically enable access.

Granting File Access to Network Service

To provide access to an ASP.NET application running as Network Service, you must grant access to the Network Service account.

To grant read, write, and modify permissions to a specific file

  1. In Windows Explorer, locate and select the required file.
  2. Right-click the file, and then click Properties.
  3. In the Properties dialog box, click the Security tab.
  4. On the Security tab, examine the list of users. If the Network Service account is not listed, add it.
  5. In the Properties dialog box, click the Network Service user name, and in the Permissions for NETWORK SERVICE section, select the Read, Write, and Modify permissions.
  6. Click Apply, and then click OK.

Your ASP.NET application can now write to the specified file.