Friday, October 03, 2014

Configure app which requires admin rights to run at startup with task scheduler


App which requires elevated admin rights can’t just be set to run at startup by adding it to the registry key (HKLM\Software\Microsoft\Windows\CurrentVersion\Run) because it mail fail to start since it requires the UAC prompt. Windows will silently fail to display the UAC prompt.

One solution is to make the app a Windows Service, but depending on the technology used, this might not be possible. For example, a .NET Windows Service which is using .NET API printing (System.Printing) is not recommended (see or see ‘Caution’ in

So another solution is to use task scheduler.

When configuring the scheduled task, you need to make sure:

1. In the task properties popup, "Run with highest privileges" option is checked.

2. In the "Edit Action" popup, "Start in" is filled with the directory path (Do not include quotation marks or a trailing slash)

Tuesday, September 02, 2014

Duplicate folders issue with MvvmCross by NuGet


EDIT: Issue is fixed in MVVMCROSS v3.2.1 !

With the current NuGet version of MvvmCross, when adding it to the project you get duplicate folders (‘Layout’ and ‘layout’, ‘Values’ and ‘values’)

To fix this, right click on the project and choose ‘Tools \ Edit File’ in Xamarin Studio. In Visual Studio, there’s a similar way.

In the .csproj, you just need to replace the first upper case letter with lower case letter, so replace ‘Layout’ with ‘layout’ and ’Values’ with ‘values’ and save the file.


Tuesday, August 05, 2014

Auto binding of outlets in Xamarin iOS and MvvmCross


If you are like me and you don’t like doing the bindings in code, you start thinking about solutions.

So I’m experimenting with the idea of creating the bindings at runtime, based on a simple name convention:

  • An UIButton outlet with the name 'btnXXX' is bound to the view-model 'XXXCommand' property.
  • An UITextField outlet with the name 'txtXXX' is bound to the view-model 'XXX' property.
  • An UILabel outlet with the name 'lblXXX' is bound to the view-model 'XXX' property.

For example, if you have a UIButton outlet called btnLogin, it's bound to view-model LoginCommand property.

I uploaded the code here;

This can be done for other platforms as well.

Tuesday, July 29, 2014

Xamarin HttpClient NameResolutionFailure exception


If you look on internet there are plenty of people reporting this error.

Xamarin is somehow aware of this error, and it marked it as fixed but it doesn’t seem like it is.

Fortunately, this exception appears only in debug mode, not in release mode.



When trying to deploy on device I got this error:

Deployment failed because of an internal error: Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE]

Deployment failed. Internal error.

To fix it, run:

C:\Users\[YourUserName]\AppData\Local\Android\android-sdk\platform-tools>adb uninstall

Don’t include the .apk file extension

Monday, May 26, 2014

Publish empty folders


If you need to include an empty folder when deploying using MSDeploy (either manually from Visual Studio or calling msdeploy from scripts) you can do that by:

1. create a Web Publishing Pipeline file (.wpp.targets)

   Create a new XML file in the project folder (the same folder that holds the .csproj or .vbproj file) and name it <projectname>.wpp.targets.

2. Add the following

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="">
  <Target Name="MakeEmptyFolders">
    <Message Text="Adding empty folder to hold downloads" />
    <MakeDir Directories="$(_MSDeployDirPath_FullPath)\Survey\responses"/>

In my case I needed an empty folder called ‘responses’ inside an existing ‘Survey’ folder.

The folder will be created no matter which configuration or publishing profile is run.

More info:

Monday, April 07, 2014

A busy MvxViewController for MvvmCross + iOS

In my MVVMCross apps, in the shared PCL core library, I usually have a MvxViewModel derived class called ViewModelBase with a IsBusy property:

public class ViewModelBase : MvxViewModel
bool isBusy;
public bool IsBusy
get { return this.isBusy; }
set { if (this.isBusy != value) { this.isBusy = value; this.RaisePropertyChanged("IsBusy"); } }

// other base stuff in ViewModelBase
The property is to update a progress indicator control in the view.
For iOS the control can be UIActivityIndicatorView.

But instead of placing a UIActivityIndicatorView on each view, we can dynamically create it at run-time when IsBusy property changes to true.
We can have this implemented in a ViewController base class like this:

using System;
using System.ComponentModel;
using MonoTouch.ObjCRuntime;
using MonoTouch.UIKit;
using Cirrious.MvvmCross.Touch.Views;
using Cirrious.CrossCore.WeakSubscription;
using YourApp.Core.ViewModels;

namespace YourApp.Touch
public abstract class MvxViewControllerBase : MvxViewController
// weak subscription to NotifyProperty event
IDisposable npSubscription;

public override void ViewDidLoad()

// subscribe to view-model's PropertyChanged
this.npSubscription = ((INotifyPropertyChanged)this.ViewModel).WeakSubscribe<bool>("IsBusy", (s, e) => { this.UpdateActivityIndicatorView(); });

// at this point view-model exists, so update the indicator view

// add other common UIViewController stuff

protected override void Dispose(bool disposing)
if (disposing && this.npSubscription != null)
this.npSubscription = null;

void UpdateActivityIndicatorView()
// get the activity indicator
var activityIndicatorView = (UIActivityIndicatorView)this.View.ViewWithTag(1000);

var vm
= (ViewModelBase)this.ViewModel;
if (vm.IsBusy)
// show busy indicator. create it first if it doesn't already exists
if (activityIndicatorView == null)
= new UIActivityIndicatorView(this.View.Frame)
= UIActivityIndicatorViewStyle.Gray,
= 1000


// show the activity indicator
activityIndicatorView.Hidden = false;
// hide the activity indicator
if (activityIndicatorView != null)
= true;
Instead of having a base class we can delegate the implementation to an extension class which has the same implementation.

Please let me know if you see any possible issues.

I am thinking to do a similar implementation for other platforms as well.
Maybe MVVMCross could support out of the box a similar implementation. A built in implementation in MVVMCross would probably require to be able to override the style for the indicator.

Thursday, March 27, 2014

Sharing library project across solutions and NuGet

Latest NuGet doesn't rely on 'Enable NuGet Package Restore’ feature:
So instead I recommend checking this:,category,DevelopmentNuGet.aspx

I have several applications using one library where communication to the backend API is implemented.
Here’s how the folder hierarchy for projects looks like
Each app solution (App1, App2) has Api.csproj added.
The main reason why Api project is added to app solutions is we want to debug and step into the code of Api library easily.
But this might not be a good idea because each app can depend on a specific version of the Api library. If something needs to be changed in the Api which affects all applications, all applications would need to be updated and sometimes the impact of the changes in the app is complex.
For this reason, we might want to have each app depending on a specific version of the Api, so instead of adding the project as reference, we could add the compiled library as reference.
We can solve the problem to step into the library source code by also having library.pdb files along with the .dll.
More info: (see comment)

However, suppose we still want to add the library as source code to app solutions.
There’s a problem with NuGet that it’s creating ‘packages’ folder per solution.
Here’s how to do it:
  1. delete existing ‘package’ folder in each solution folder
  2. for each solution, right-click on the solution file in the solution explorer > ‘Enable NuGet Package Restore’
  3. this will create a .nuget folder. open the NuGet.config
  4. add the following under <configuration> node:
      <add key="repositoryPath" value="../../packages" />
    </config> (NOTE: if you're using Xamarin, you MUST use forward slashes, otherwise on Mac you will get a folder with the name '..\..\packages' !)
    it instructs NuGet to use ‘packages’ folder located at the same level with Api and apps solution folders.
    note that this path is relative to the location of NuGet.config file
  5. go to each .csproj and make sure all paths which reference ‘packages’ folder are set to “..\..\packages’
  6. delete each ‘.suo’ file in solution folders
  7. reopen Visual Studio
  8. open each app solution and build it.
    for the first solution being built, NuGet brings the packages in the new ‘packages’ folder.
    all other solutions will reference the already downloaded packages


Friday, March 14, 2014

Install GooglePlay in emulator


I am using the info from

1. Go to and get the latest .zip compatible with your target device.
    Note the “Not compatible with x.x.x!” remarks

2. Start your emulator:

cd %LocalAppData%\Android\android-sdk\tools
emulator -avd VM_NAME_HERE -partition-size 500 -no-audio -no-boot-anim

Then use the following commands:

cd %LocalAppData%\Android\android-sdk\platform-tools

# Remount in rw mode
adb shell mount -o remount,rw -t yaffs2 /dev/block/mtdblock0 /system

# Allow writing to app directory on system partition
adb shell chmod 777 /system/app

# Install following apk
adb push GoogleLoginService.apk /system/app/.
adb push GoogleServicesFramework.apk /system/app/.
adb push Phonesky.apk /system/app/. # Vending.apk in older versions
adb shell rm /system/app/SdkSetup*

Saturday, January 25, 2014

Type-safe ViewModel to ViewModel navigation in MvvmCross

In MvvmCross you can navigate between view-model's as described in the Wiki:

It's good however to use a simple type-safety mechanism.
Suppose we have a ProductViewModel which expects two arguments for initialization:

public class ProductViewModel : MvxViewModel
     public void Init(int productId, int clientId)

With a type-safe mechanism, instead of writing:

ShowViewModel<ProductViewModel>(new { productId = pid, clientId = cid });

we can write:

NavigationHelper.ShowProduct(pid, cid);

where NavigationHelper is a simple utility class:

using Cirrious.CrossCore;
using Cirrious.MvvmCross.ViewModels;
using Cirrious.MvvmCross.Views;
using MyApp.Core.ViewModels;
using Cirrious.MvvmCross.Platform;

namespace MyApp.Core.Common
    public static class NavigationHelper
        public static void ShowProduct(int productId, int clientId)
            ShowViewModel<ProductViewModel>(new { productId = productId, clientId = clientId });

        static void ShowViewModel<T>(object parameter) where T : IMvxViewModel
            var viewDispatcher = Mvx.Resolve<IMvxViewDispatcher>();
            var request = MvxViewModelRequest.GetDefaultRequest(typeof(T));
            request.ParameterValues = ((object)parameter).ToSimplePropertyDictionary();

using Cirrious.MvvmCross.Platform; namespace statement is important because it contains the ToSimplePropertyDictionary() extension method implemented by MvvmCross.

Furthermore, instead of using the NavigationHelper class, we can move the ShowViewModel method to a ViewModelBase class:

public class ViewModelBase : MvxViewModel
       protected static void ShowViewModel<T>(dynamic parameter) where T : IMvxViewModel        
           var viewDispatcher = Mvx.Resolve<IMvxViewDispatcher>();            
           var request = MvxViewModelRequest.GetDefaultRequest(typeof(T));            
           request.ParameterValues = ((object)parameter).ToSimplePropertyDictionary();            

public class ProductViewModel : ViewModelBase
    public static Show(int productId, int clientId)
        ShowViewModel<ProductViewModel>(new { productId = productId, clientId = clientId });

    public void Init(int productId, int clientId)

and we can now write:

ProductViewModel.Show(pid, cid);

Having the Show method near the Init method in the ViewModel class, makes it a bit more easier to maintain the parameters.

Saturday, January 18, 2014

ASP.NET errors


#1. There is a duplicate 'system.web.extensions/scripting/scriptResourceHandler' section defined

Check .NET Framework version for app pool.

Projects developed in (2.0,3.0,3.5) should run under an Application Pool with .NET FRAMEWORK VERSION v2.0.50727 

Projects developed in 4.0 should run under an Application Pool with .NET FRAMEWORK VERSION v4.0.30319

#2. Could not load file or assembly 'System.Data.SQLite' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Make sure that "Enable 32 - Bit Applications" is set to false or true for the app pool, depending on System.Data.SQLite.dll

System.Data.SQLite.dll is a mixed assembly, i.e. it contains both managed code and native code. Therefore a particular System.Data.SQLite.dll is either x86 or x64, but never both.

#3. HTTP Error 404.3 - Not Found
The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.

Requested URL

You need to run this:

Thursday, January 16, 2014

Invalid markup in XAML in Visual Studio 2013

If you get this error in designer when there’s clearly no error in your XAML:
- close all files open in Visual Studio
- close Visual Studio
- delete the .suo file near the .sln
- delete bin and obj folders

if still doesn't work you can try to delete all directories from:

More info:

Monday, January 13, 2014

Installing Windows 8 and customization

1. Use Windows 7 USB/DVD download tool to create a Windows bootable USB drive

2. If you want to create a Windows x64 bootable image, you need to run the Windows 7 USB/DVD download tool from a x64 Windows computer.

3. During the Windows 8 installation if you encounter error while installing \ copying files, and it’s at the same point (same percent), then the USB image is corrupted.

4. If doing Android dev. with Intel x86 Emulator Accelerator (HAXM), you must disable Hyper V in Windows.
disable: bcdedit /set hypervisorlaunchtype off
re-enable (restart): bcdedit /set hypervisorlaunchtype auto
5. For Samsung 840 Pro SSD: Install Samsung Magician
It will start on each Windows start but it’s annoying it shows UAC. One solution is to remove it from startup

C:\users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup
6. There are a number of SSD optimizations to be done

7. Disable Windows Narrator. it’s annoying it starts anytime Windows Key + Enter are pressed.
8. Make Word to minimize to tray: right click on tray icon and choose “Hide when minimized
9. Automatically user login
1. run netplwiz 
2. uncheck the “Users must enter a user name and password to use this computer”, click Apply
3. enter username and password
10. Force Visual Studio always run as admin

In Windows 8, you have to right-click devenv.exe and select "Troubleshoot compatibility".
  1. select "Troubleshoot program"
  2. check "The program requires additional permissions"
  3. click "Next", click "Test the program..."
  4. wait for the program to launch
  5. click "Next"
  6. select "Yes, save these settings for this program"
  7. click "Close"
11. On Windows 8, make sure you get the latest Intel x86 Emulator Accelerator (HAXM), At this moment, the one from Android SDK manager is buggy on Windows 8.