Blog Archives

Could not load type System.ServiceModel.Activation.HttpModule’ from assembly ‘System.ServiceModel, Version=, Culture=neutral, PublicKeyToken=

If you already have .Net 4.0 installed and install a program that brings in an earlier version of .Net, or manually install an earlier version of .Net afterwards, you may get an exception page that matches the title of this article.

This is a simple fix, outlined in detail in MSDN article referenced at the bottom.

Navigate to:


%windir%\Microsoft.NET\Framework64\v4.0.30319 (on a 64-bit computer)


aspnet_regiis.exe /iru

That’s it!


ubuntu lts 12 xrdp rdp setup on Amazon Cloud AWS(12.04.3 precise pangolin)

Consolidated from multiple sources to exclude erroneous steps.

Tested on Amazon Web Services fresh Ubuntu LTS 12.04.3 instance.

Decided upon ubuntu vs centOS simply to avoid having to compile xrdp and manage dependencies manually. Chose 3rd party linux over Amazon AMI in this case for benefit of included repos, use cases and support in their respective communities (ubuntuforums, etc), as well as not having to compile xrdp in Amazon AMI.

sudo useradd -m {name}
passwd {name}

#you may want to consider setting a root passwd in case you mess up sudoers. if you make a mistake with sudoers terminate your instance and relaunch 🙂 ... or you could mount the HD with another system if it's unencrypted and modify sudoers
passwd root

#edit /etc/sudoers.d and add your new user
{name} ALL=(ALL) ALL

#edit sshd /etc/ssh/sshd_config disable root login and allow password authentication (if you like)
service ssh restart

sudo apt-get install xrdp

sudo apt-get install gnome-session-fallback

#two options, 2d unity no longer available, previously
echo "gnome-session --session=ubuntu-2d" > ~/.xsession
echo gnome-session --session=gnome-fallback > ~/.xsession

#make sure your user has permission to this file if you have to create it with sudo etc
chown {name}:{name} .xsession

sudo add-apt-repository ppa:gnome3-team/gnome3
sudo apt-get update
sudo apt-get install gnome-shell

sudo apt-get install lightdm

sudo /usr/lib/lightdm/lightdm-set-defaults -s gnome-fallback

Don’t forget AWS Firewall:

22 (SSH)	your ip/32

C# Create a Windows Installer Class Custom Action bootstrap DLL in .Net

The standard windows installer project included with Visual Studio right out of the box is great in many deployment scenarios.

For more advanced needs, organizations and developers usually defer to 3rd party solutions, such as InstallShield, Wise, wix or NSIS (NullSoft).

These solutions are all very well tested and have minimal learning curve in a lot of cases. However, if you are tight on budget or simply looking for the experience and full customization, you can also create your own custom action installer class in Visual Studio.

Simply create a new DLL project included in the same solution as your windows installer project. From the Windows Installer Project go to “File System” and in your Application Folder add “Project Output” and select your new DLL. Now go to the “custom actions” tab and under install and/or uninstall right click and “Add Custom Action” then select the output under Application Folder. That’s it!

Make sure the class for your DLL has “RunInstaller” attributes and looks similar to the snippet below. You may also want to do some light reading on the “CustomActionData” property to see if there are any variables you may need such as “ProductCode”.

To change the custom action data property, from the custom action tab simply select your DLL output after adding it, and expand the Visual Studio Properties tab on the side.

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;

namespace MSIBootstrap
    public partial class InstallHelper : Installer
        public static string InstallTitle = "Discount Notes"; //used by install/uninstall to get window handle
        public InstallHelper()

        public override void Install(System.Collections.IDictionary stateSaver)
try {
//your custom code
catch (Exception ex) {
throw new InstallException(ex.ToString());

 public override void Uninstall(System.Collections.IDictionary stateSaver)
//mimic same try/catch design pattern if you like

With this approach, you are essentially using the standard windows installer project to bootstrap your custom action DLL.

This is very powerful, and allows you to define your own code logic and conditions as well as custom interfaces and forms designed directly from within Visual Studio.

Wise installer,
wix installer,
Nullsoft NSIS,
Wikipedia (bootstrapping),,, (persisting savedState),
MSDN, “CustomActionData”,

Call Cancel from Custom Action in .Net Windows Installer Project

As an alternative to using the “Rollback” or “InstallException” approach, simply use pinvoke/interop to call the cancel button on the base installer form directly.

(see my related post for more detail and full code)

ShowWindow(msiwindowhandle, ShowWindowCommands.Show);
                IntPtr cancelbuttonhandle;
                const int BM_CLICK = 0x00F5;
                msiwindowhandle = FindWindow("#32770", InstallTitle);
                cancelbuttonhandle = FindWindowEx(msiwindowhandle, IntPtr.Zero, "Button", "Cancel");
                SetActiveWindow(msiwindowhandle); //necessary for button click to fire
                SendMessage(cancelbuttonhandle, BM_CLICK, IntPtr.Zero, IntPtr.Zero);


the savedstate dictionary does not contain the expected values and might have been corrupted

This is a common error with custom action development, especially if you are working with your own custom installer class, not using wix or some other windows installer derivative.

Since many of the Google entries for this were unresolved, thought I would give it a quick tackle. 😉

First Solution

Throw an exception.

This solution seems to be the most popular among Google results.. You can throw a new Exception or InstallException, but this creates an unsightly error message which you would not want your users to see.

 public override void Install(System.Collections.IDictionary stateSaver)
            Process proc = new Process();
            string path = Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(InstallHelper)).Location);
            proc.StartInfo.FileName = path + "\\somesubprocess.exe";
//note ProductCode argument is an installer variable
            proc.StartInfo.Arguments = "\"" + this.Context.Parameters["action"] + "\" \"" + this.Context.Parameters["ProductCode"] + "\" \"" + this.Context.Parameters["src"];


//optional showwindow code to force window into foreground
 IntPtr msiwindowhandle;
            msiwindowhandle = FindWindow("#32770", InstallTitle);
            ShowWindow(msiwindowhandle, 0);

if (proc.ExitCode == 1)
throw new InstallException("Installation cancelled. Any changes made will now rollback.");
                if (stateSaver == null)
                    stateSaver = new Dictionary<string, string>();
                    //Add some default values to the dictionary here...if you dare..

                base.Rollback(stateSaver); //will give you article title error

The code above was a bit much to simply explain the concept of throwing a new “InstallException”, but does illustrate there are definitely things you can do from your custom action bootstrap DLL which have room for error (like spawning a sub process!).

The Alternative

…is to simply click/call the cancel button for the base installer from your custom action code.

Since the msi installer process is separate from your bootstrap custom action DLL, you will have to use some old school tricks to work around the constraints.

Simply import User32.dll and call the “SendMessage” function, passing in the handle of cancel button. See code example below:

using System.Runtime.InteropServices;

[DllImport("User32.dll", EntryPoint = "SendMessage")]
        public static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);

        [DllImport("user32.dll", SetLastError = true)]
        private static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);

        [DllImport("user32.dll", SetLastError = true)]
        public static extern IntPtr SetActiveWindow(IntPtr hWnd);

        [DllImport("user32.dll", SetLastError = true)]
        static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

        static extern bool ShowWindow(IntPtr hWnd, ShowWindowCommands nCmdShow);

        enum ShowWindowCommands : int

            Hide = 0,
            Normal = 1,
            ShowMinimized = 2,
            Maximize = 3,   
            ShowMaximized = 3,
            ShowNoActivate = 4,
            Show = 5,
            Minimize = 6,
            ShowMinNoActive = 7,
            ShowNA = 8,
            Restore = 9,
            ShowDefault = 10,
            ForceMinimize = 11

public static string InstallTitle = "AppbarTitle"; //used to get the window handle

  public override void Install(System.Collections.IDictionary stateSaver)
ShowWindow(msiwindowhandle, ShowWindowCommands.Show);
                IntPtr cancelbuttonhandle;
                const int BM_CLICK = 0x00F5;
                msiwindowhandle = FindWindow("#32770", InstallTitle);
                cancelbuttonhandle = FindWindowEx(msiwindowhandle, IntPtr.Zero, "Button", "Cancel");
                SetActiveWindow(msiwindowhandle); //necessary for button click to fire
                SendMessage(cancelbuttonhandle, BM_CLICK, IntPtr.Zero, IntPtr.Zero);

The MSDN Social article listed in my references below comes up in Google rankings high for the error the OP received when calling the Rollback method manually. To track any social momentum my solution may possibly gain, refer to this link.

MSDN Social,
MSDN, “Installer.Rollback Method”,
MSDN, “Installer.BeforeRollback Method”,

Create an Uninstall Shortcut for Windows Installer in C#

When utilizing the windows installer project type bundled with Visual Studio I was very surprised to find there was no simple functionality to add an uninstall shortcut.

Instead, there are a few workarounds, some better than others but overall going to have to get your hands dirty to make this one work.

Option 1 – Batch File

Create an uninstall batch file and add a shortcut which points to the batch.

Only downside of this solution, which is actually the simplest, is an ugly little bugger we all know as the DOS window pops up when you execute the batch.

(courtesy of

@echo off
msiexec /x {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}

Option 2 – VBS File

No code example for this option since I didn’t even consider trying this one personally, but this would be to create the equivalent of the code above using WshShell in vbscript (which is actually a similar end result as the code in option 3).

The .vbs file would execute cleanly without a DOS prompt, but my experience with .vbs files has found that they are not AntiVirus friendly and don’t always port OS’es cleanly either. Certain API calls slightly change over time and can break syntax, and you never know if John Doe’s newest antivirus update will flag your .vbs file and prevent it from executing.

Option 3 – Roll up those sleeves

Create a separate app which calls msiexec either by instantiating a hidden cmd.exe process window, or calling it directly also using process object. Then add this separate app to your deployment project solution and create a shortcut in the installer which points to the primary output of your separate app project.

Using this method is the most work, but the best end result for the consumer IMO (isn’t that usually how it works? :P). If you wanted, you could even create your own uninstall process and run msiexec in “unattended” a.k.a “silent” mode and uninstall your app quietly in the background.

(courtesy of

using System.Diagnostics; //namespace containing process RD

public partial class App : Application
  void Application_Startup(object sender,StartupEventArgs e)
    for(int i = 0;i != e.Args.Length;++i)
      if(e.Args[i].Split('=')[0].ToLower() == "/u")
        string guid = e.Args[i].Split('=')[1];
        string path = Environment.GetFolderPath(Environment.SpecialFolder.System);
        ProcessStartInfo uninstallProcess = new ProcessStartInfo(path+"\\msiexec.exe","/x "+guid);

Keep in mind in all of these scenarios, the application guid is necessary to pass as a parameter to msiexec. To pass this variable you will need to specify the productcode as a parameter in custom action data.

Such as:

CustomActionData => /productcode = [ProductCode]

I believe [ProductCode] may also be case sensitive, as I had originally specified “PRODUCTCODE” in one of my installers but this did not seem to pass through..


If you’re still reading by this far (and yes I tried to blow up however to draw your eyes), keep in mind your uninstall executable or batch is calling msiexec, not the other way around, so “ProductCode” is not yet part of the mix.

I’ve yet to find the cleanest solution to this final issue, but overall my thoughts would be to pass product code through to a different separate application added to your deployment project solution as part of the install process, and have this application either store the product code in a generic location such as:


…or, still using your “install helper” application, store it somewhere in the application directory in program files created by the installer. Essentially the same thing as application data, just leaves less chance of any traces of your program being left behind on uninstall.

Enjoy. 😉

Windows Installer (Relevant links for Custom Actions),,,,,
MSIexec command line options,
Flexera Software,

Missing MySQL References in PHP

The following can be used for quick LAMP installation and/or if you are missing MySQL references in PHP.


sudo apt-get install mysql-server
sudo apt-get install apache2
sudo apt-get install php5
sudo apt-get install php5-mysql
sudo apt-get install phpmyadmin


sudo -c "yum install mysql-server"
sudo -c "yum install apache2"
sudo -c "yum install php5"
sudo -c "yum install php5-mysql"
sudo -c "yum install phpmyadmin"