Visual Studio 2005 -> 2008/10 Service Installer Project Upgrade issue (Inn-sights of DotNet Installer)

Recently my team was working on a task of Framework up-gradation from 2.0 to 4.0 during which they were struggling with upgrading of Dot Net Installers for some of the foundation softwares + SDK installers.

The anxiety was at its best when just before last day of my sprint I found some hint on one my favorite sites StackOverflow.

This is one reason which prompts me write/share/help people know some of the dark sides of Microsoft which they do behind the scenes. Yes time and again I am here with my experience of this very interesting problem.

The funny side of this problem is the tool i used for identifying and resolving this issue is a tool by Microsoft itself…Orca.exe.

Orca.exe is a database table editor for creating/editing/debugging Windows Installer packages.

Problem Statement:

Update an existing dot net installer created using VS2005 having custom Installer class used in custom actions which installs/uninstalls windows services. I would call this “Visual Studio 2005 -> 2008/10 Service Installer Project Upgrade issue“. This issue is not usually faced in web installers.

Every time we convert this installer project from Framework 2.0 to Framework 4.0 using VS2010 and run the compiled msi on a system with older version of this software to upgrade we get typical ERROR 1001 stating “The specified service already exists”. This is because the installer was not able to upgrade by removing the older version before installing the new one.

Here I would like to emphasis more on System Upgrade as we were not facing any issue on a fresh install. Generally, in order to make your msi up gradable we generally set the RemovePreviousVersions property of the installer to True and change the GUID and Assembly Version so that msi can auto detect for the system upgrade. Perhaps this behavior FAILS when we compile installer projects in VS2008 or above.

Solution:

If you have set both install and uninstall custom actions in an application’s setup project, and you have enabled the RemovePreviousVersions property in Visual Studio 2005, the previous version of the product is uninstalled during an upgrade. However, this behavior changed in Visual Studio 2008 as follows:

In Visual Studio 2005, the custom actions were called as follows on an upgrade from v1.0.0 to v1.0.1:
v1.0.0 custom action Uninstall()
v1.0.1 custom action Install()
In Visual Studio 2008, the uninstall action is not called, as follows:
v1.0.1 custom action Install()

If you created custom actions relying on the old behavior, you need to modify your code for the new behavior. This behavior change affects only updates, not uninstalls.

CRUX:

So how to “Put the VS2008 behaviour back to how it worked in VS2005” (the old versions Uninstall custom action is called before the new version Install) .

Orca is the solution….

Steps:

  1. Open your compiled MSI using Orca.exe
  2. Select “InstallExecuteSequence” table from the left pane
  3. Change the #sequence number of “RemoveExistingProducts” to immediately after InstallInitialize.

Screen Shot with position of RemoveExistingProduct in VS2010 compiled project

RemoveExistingProduct Sequence in VS2010

Screen Shot after Re-positioning of RemoveExistingProduct using Orca.

RemoveExistingProduct Sequence in VS2005

Here you go…with the three step solution!!!

Happy Coding!!! 🙂

How to get Hotmail Contacts using Windows Delegated Authentication

From past one week i have been scratching head to fulfill one of my projects business requirement to get Hotmail Contacts email address using Windows Live Connect API but the LIVE connect developer SDK says due to privacy reasons we do not expose users contact email address. The Hotmail Contact API returns contact basic info along with EMAIL HASH which is of no use 🙁 .

After digging deep i found that there are couple of sites which are extracting Hotmail users contact Email Address. Like LinkedIn, EduGraph etc. On getting even deeper to understand how these sites are doing using some of the popular developer digging tools like the FIDDLER i got to know about the an OBSOLETE Microsoft API named DELEGATED AUTHENTICATION.

The Links related to Delegated Authentication clearly says :

This topic describes functionality that will be obsolete. This functionality is provided only to support legacy applications. Live Connect incorporates features that provide equivalent functionality.

Please note the last statement “Live Connect incorporates features that provide equivalent functionality”. BIG LIERS …….

On visiting LIVE connect developer guide reference it says:

Note  For user privacy reasons, we do not provide access to the email and address info of a user’s contacts.

Anyways somebody has to consolidate all this info for the benefit of others so let me take this opportunity for the sake of other developers…. 🙂

Steps to get Hotmail Contacts using Delegated Authentication:

Register Application

  1. Register your application using the link: RegisterApp.
  • Provide Application Name
  • Privacy Url – Note: The Url domain should be FQDN(Fully qualified domain name). You cannot provide “localhost” or IP in the Url.
  • Redirect domain – This Url will be the callback url of your application where microsoft will redirect user back after successful sign in and getting the necessary user consent for the data access in this case it will be “delauth-handler.aspx“. Note: The Url domain should be FQDN(Fully qualified domain name). You cannot provide “localhost” or IP in the Url.
  • Get the ClientId and ClientSecret. This will be the Gate pass for your application to communicate with Microsoft Contacts API.
  • Creating Sample App
    1. Create sample Website in IIS with fully qualified domain name. The domain name should be same as you provided in the RedirectUrl at the time of registering application. for ex: “www.HotmailLiveContacts.com”.
    2. Update the web.config file with:
    • wll_appid – This is the client Id you got after registering your application.
    • wll_secret – This is the client secret you got after registering your application.
    • wll_returnurl – This is the Redirect Url provided while registering your application.
    • wll_policyurl – This is the Policy Url provided while registering your application.
  • Get the consent url(login url) by initializing the “WindowsLiveLogin” class “GetConsentUrl” method. This is required to make the user login and provide necessary consent for the data access.
  • Extract the consent token from the response by calling”WindowsLiveLogin” class “ProcessConsent” method.
  • Screen shot for the Concent:

    ConsentToken from Microsoft

    Get Hotmail Contacts

    Now comes the final process for which the blog has been created. Getting the Hotmail contacts.

      1. Create a HttpWebRequest with the below URL
    • HttpWebRequest request = (HttpWebRequest)WebRequest.Create(string.Format(“https://livecontacts.services.live.com/users/@[email protected]{0}/rest/livecontacts”, intlid)); //intlid refers to LocationId
    • request.Headers.Add(“Authorization”, “DelegatedToken dt=\”” + token + “\”“); //token refers to Delegation Token.
  • Get the ResponseStream into the StreamReader in the form of XML.
  • There are couple of handy links which you can use:
    1. Manage registered applications: Click Here
    2. Delegated Authentication Error Codes: Click Here
    3. Manage you shared information. You can revoke access to this information at any time using: Click Here
    4. Link to the source code: Click Here
    Hope the article would be helpful!!! 🙂


    Three main categories of design patterns?


    There are three basic classifications of patterns Creational, Structural, and Behavioral patterns.
    Creational Patterns

    • Abstract Factory:- Creates an instance of several families of classes
    • Builder: – Separates object construction from its representation
    • Factory Method:- Creates an instance of several derived classes
    • Prototype:- A fully initialized instance to be copied or cloned
    • Singleton:- A class in which only a single instance can exist

    Note: – The best way to remember Creational pattern is by ABFPS (Abraham Became First President of States).
    Structural Patterns

    • Adapter:-Match interfaces of different classes.
    • Bridge:-Separates an object’s abstraction from its implementation.
    • Composite:-A tree structure of simple and composite objects.
    • Decorator:-Add responsibilities to objects dynamically.
    • Façade:-A single class that represents an entire subsystem.
    • Flyweight:-A fine-grained instance used for efficient sharing.
    • Proxy:-An object representing another object.

    Note : To remember structural pattern best is (ABCDFFP)
    Behavioral Patterns

    • Mediator:-Defines simplified communication between classes.
    • Memento:-Capture and restore an object’s internal state.
    • Interpreter:- A way to include language elements in a program.
    • Iterator:-Sequentially access the elements of a collection.
    • Chain of Resp: – A way of passing a request between a chain of objects.
    • Command:-Encapsulate a command request as an object.
    • State:-Alter an object’s behavior when its state changes.
    • Strategy:-Encapsulates an algorithm inside a class.
    • Observer: – A way of notifying change to a number of classes.
    • Template Method:-Defer the exact steps of an algorithm to a subclass.
    • Visitor:-Defines a new operation to a class without change.

    Note: – Just remember Music……. 2 MICS On TV (MMIICCSSOTV).