Cryptic Error Messages

Posted on 15 Oct 2009 05:23 under humour software windows

We all read a lot about funny and cryptic messages. But it was surprising to see that in top of the line, latest product:


Sorry Microsoft, may be I am not educated enough but I couldn't understand what you mean by error 0x80070643…


Writing WCF Wrapper and Catching Common Exceptions

Posted on 19 Aug 2009 09:06 under c# code

Suppose you have a WCF proxy class which calls some remote methods. Instead of calling remote methods, lets take the example of a similar class:

public class WcfProxy //calling methods of this class may raise exceptions
    //Method with one string parameter
    public void function1 (string s) {
        if (String.IsNullOrEmpty (s))
            throw new CommunicationException ("Its my nature to throw exceptions...");
        Console.WriteLine ("I am in function1");
    //Method with one int parameter
    public void function2 (int i) {
        if (i == 0)
            throw new TimeoutException ("I like to throw exceptions and spoil your day...");
        Console.WriteLine ("I am in function2");
    //method with one ref parameter
    public void function3 (ref string s) {
        if (String.IsNullOrEmpty (s))
            throw new CommunicationException ("Its my nature to throw exceptions...");
        s = "function3 executed successfully.";
        Console.WriteLine ("I am in function3");
    //method with return parameter
    public string function4 () {
        Console.WriteLine ("I am in function4");
        return "function4 executed successfully.";

Now I want to write a wrapper class which will call these function on my behalf and catch the common exceptions related to communication problem. Instead of calling these functions and catching exceptions after every call, we can use generic functions which will call the functions and catch exceptions if raised.

//declare the delegates that are NOT provided by .NET framework
public delegate void ActionReference<T> (ref T t1);
public delegate T ActionReturn<T> ();
public class ProxyWrapper
    private readonly WcfProxy proxy = new WcfProxy ();
    public bool Success { get; set; }
    public string Message { get; set; }
    private void ExecuteAndCatch<T> (Action<T> action, T t) {
        try {
            action (t);
            Success = true;
        catch (TimeoutException) {
            Success = false;
            Message = "Timeout exception raised.";
        catch (CommunicationException) {
            Success = false;
            Message = "Communication exception raised.";
    private void ExecuteAndCatch<T> (ActionReference<T> action, ref T t) {
        try {
            action (ref t);
            Success = true;
        catch (TimeoutException) {
            Success = false;
            Message = "Timeout exception raised.";
        catch (CommunicationException) {
            Success = false;
            Message = "Communication exception raised.";
    private T ExecuteAndCatch<T> (ActionReturn<T> action) {
        T result = default(T);
        try {
            result = action ();
            Success = true;
        catch (TimeoutException) {
            Success = false;
            Message = "Timeout exception raised.";
        catch (CommunicationException) {
            Success = false;
            Message = "Communication exception raised.";
        return result;
    public void function1 (string s) {
        ExecuteAndCatch (proxy.function1, s);
    public void function2 (int i) {
        ExecuteAndCatch (proxy.function2, i);
    public void function3 (ref string s) {
        ExecuteAndCatch (proxy.function3, ref s);
    public string function4 () {
        return ExecuteAndCatch<string> (proxy.function4);
    //more functions can be called here...

Now we can test the wrapper class in main method:

public static void Main () {
    ProxyWrapper w = new ProxyWrapper ();
    w.function1 ("");
    Console.WriteLine (w.Success ? "Success!" : "Failed: " + w.Message);
    w.function2 (0);
    Console.WriteLine (w.Success ? "Success!" : "Failed: " + w.Message);
    var s1 = "Initial";
    w.function3 (ref s1);
    Console.WriteLine (w.Success ? "Success! " + s1 : "Failed: " + w.Message);
    var s2 = w.function4 ();
    Console.WriteLine (w.Success ? "Success! " + s2 : "Failed: " + w.Message);
    Console.ReadLine ();

And here is the output:

Failed: Communication exception raised.
Failed: Timeout exception raised.
I am in function3
Success! function3 executed successfully.
I am in function4
Success! function4 executed successfully.

This solution is developed from the answer given to my question on StackOverflow. You can download the complete source file here.


How to generate a unique machine signature

Posted on 13 Aug 2009 12:06 under software tips-&-tricks

During a recent project, I had to solve a problem which is NOT really new:

Creating a signature using computer hardware that uniquely identifies it!

I didn't want to depend of software characteristics because I didn't want the signature to change even if user decides to change or install new operating system.

I used uncle Google extensively and came across many resources such as:

I learnt following things in the process:

  1. I quickly found that most hardware information can be accessed using WMI only. Since WMI is not available below Windows 2000, I tried to find other alternatives but couldn't find any. I could get the volume serial number using Windows API but that was not enough. So WMI seems to be only viable choice.
  2. Using MAC address for machine signature generation is generally a bad idea because many manufactures allow you to change it and you can have multiple MAC addresses if someone is using more than one connection (think of someone using laptop connected to a LAN and also a WIFI network)
  3. Using Processor ID used to work in earlier days but somehow Intel has decided to stop giving unique processor ID to each processor these days.
  4. It is not right to rely on only one hardware parameter considering the dynamic advancement in computer hardware industry (Multi core processor are so common these days)

To easily analyse the computer hardware parameters, I created an application which uses WMI to get hardware information. I called it Machine Explorer! You can download the application freely and have fun with it.

Here is how it looks like:


I found out that some serial numbers such as BIOS serial number and Motherboard serial number are unique and they are not likely to change also. There might be other candidates which you explore (do let me know if you find any).


Dual boot Vista and OSX on HP Laptop

Posted on 04 Aug 2009 14:01 under osx tips-&-tricks

Disclaimer: Installing Mac OSX on non-apple hardware is illegal. This post is just for educational purpose.

My laptop configuration:

HP Laptop dv6000t
Processor: Intel Core Duo CPU T2450 @ 2.00 GHz
Memory (RAM): 1GB
Audio: Conexant High Definition Audio
Display: Mobile Intel(R) 945 Express Chipset Family
Network: Intel(R) PRO/100 VE Network Connection (Ethernet), Intel(R) PRO/Wireless 3945ABG Network Connection

What you need


You will need to get hold of iATKOS DVD. You can find it at usual places. I used iATKOS v 7.0. Download the disk image and burn the DVD.

Windows Vista DVD

You will need it to repair Windows Vista startup. If you have Windows Vista DVD (system recovery disk) which came with your laptop, it won't work. You need a bootable Windows Vista Disk.

chain0 file

You will need this file to make your PC dual bootable. Click here to download this file.


Prepare a Partition

You will need to configure a partition on which you will install Mac OSX. If you already have a partition, you are good to go. If you don't have one, you need to create it. You can do so by resizing an existing partition. Various posts mentions using Windows Disk Management for doing it. You can also try this. Right click my computer, click "Properties", Click "Device Manager"on left pane, Click "Disk Management". This will show all the existing partitions. Right click the target partition and click "Shrink Volume". You can select the amount of space to free and click OK.

However I found Disk Management of Windows pretty crappy because it almost always didn't allow me to free space even when there is plenty of space left on hard disk. This is because Windows only lets you shrink the largest continuous chunk of free space.

This is where I found EASEUS extremely useful. The free home edition works just fine. It has a similar interface as Windows Disk Management, so you can create the partition using it very easily.

Format the partition as NTFS and apply the volume label "OSX".

Installing OSX

  • Insert the DVD in the tray and boot your computer from it. You may need to change your boot order if your computer doesn't boot correctly.
  • Press F8 as the count down begins and type -v at the prompt and hit enter. This will make the startup verbose so that you can see the startup messages.
  • After a while you should be looking at the leopard installer. Follow the on screen instructions.
  • Once the loading bar vanishes, select Utilities > Disk Utility.
  • Select the volume "OSX" which you created previously and format it as MAC OSX Journaled Extended.
  • Now get back to the Leopard install screen. Choose the partition which you just formatted.
  • Customise the installation option and:
    • Unselect
      • Chamleon boot loader (We will be using Windows boot manager so we don't need it)
    • Select
      • Intel EFI String
      • GMA 950 for Laptop
      • Apple PS2 Drivers
  • Continue the installation. It will take a while so you can have a coffee.

Making it dual bootable

  • Once the installation is done, reboot with the DVD in the drive. Press F8 at Darwin boot loader and type -s and press enter.
  • Execute the following commands:
fdisk -e /dev/rdisk0
flag 1
  • Now before the PC starts, remove the DVD. You will not be able to boot into Vista and instead get an error "winload.exe is corrupt"
  • Now insert the Vista bootable disk in the drive and reboot from DVD. Click on "Repair computer" once you are inside the DVD and it will automatically detect if a problem exists and suggest "Repair and Restart". Press the same and remove the DVD once the PC is about to restart. You should now be able to log in to vista without any problem.
  • Boot into Vista. Copy the chain0 file to C:
  • Open the command prompt with elevated admin privileges from the start menu.
  • Type the following into the prompt
bcdedit /copy {current} /d "Mac OS X"
bcdedit /enum active
bcdedit /set {GUID} PATH \chain0

In the first command type {current} as it is, literally..nothing else. Just {current} with the curly brackets. In the third command replace the GUID with the alphanumeric GUID you see against "Identifier" for Mac OSX. You will see this as soon as you enter the second command.

  • Now again give command "bcdedit /enum active" and confirm that you have Mac OSX correctly configured. It must look something like:

Windows Boot Loader

identifier {e94e2940-68da-11de-b9a9-8cf8abd2fc0f}
device partition=C:
path \chain0
description Mac OS X
recoverysequence {572bcd55-ffa7-11d9-aae2-0007e994107d}
recoveryenabled Yes
osdevice partition=C:
systemroot \Windows
resumeobject {17cbdd92-6953-11de-909d-806e6f6e6963}

  • Close the command prompt and restart your laptop.
  • You should be looking at the screen with two options to boot into Mac OSX or Vista. Select the operating system you want to boot into. Hurray!!!

What works

  • HP quick launch keys (the blue touch buttons above keyboard)
  • Web cam
  • Remote
  • Accessing files from windows NTFS drives

What still does not work

  • After following above steps, I couldn't get the network working (Wireless and ethernet both). I am still in the process of fixing it.


Most of the steps and guide come from this excellent article.


How NOT to confirm when user is leaving without saving his work

Posted on 09 Jul 2009 13:32 under life software

Confirmation dialogs are useful in some situations but mostly they suck. They suck because programmers overuse them a lot and instead of showing real dialog, they try to frame the question such that it fits in fixed "Yes/No/Cancel" or "OK/Cancel" format. It makes it impossible for a user to determine what is being asked without actually reading whole text.

But this one is worse. It is so effective that it still catches me sometimes. I am talking about .NET Reactor. So you open this nice little application and do something with it. And then you decide to close it. It shows following screen:


Now this type of dialog is common. A lot of application confirms when you are leaving the application without saving your work. But what you normally get is:

There are some unsaved changes in document. Would you like to save them?

And you normally say "NO" to that dialog and get away. But .NET reactor is evil in this regard. It asks this question in a way that you have to say "YES" to get away.

To be fair to .NET reactor, its not necessarily wrong. But doing something different than most other software irritates the users. It sure irritates me.


>> Visit the complete archives to read more