Thursday, October 29, 2009

MSVCR100.dll was not found. Reinstalling ... (FIX)

Searching the web for how to fix this will frustrate you to death. The fix is to download the latest .NET SDK (4.0 in this case) and run the installer. Download the redistributable exe, not the web downloader.

Download Link: http://www.microsoft.com/downloads/details.aspx?FamilyID=ded875c8-fe5e-4cc9-b973-2171b61fe982&displaylang=en#filelist

So much for the web, MSDN or Bing search on MSDN adding any value.

Wednesday, October 28, 2009

The Visual Studio Clipboard Ring

Here's a quasi-funny story. I didn't know C# when I worked at Microsoft, and oh god no I didn't use Visual Studio to write code at Microsoft either. ViM was my editor of choice at M$. Fast-forward to today; Amazon is paying me to build C# applications and libraries. I would use ViM to write C#, but VS 2008 is the cat's whiskers when it comes to .NET development.

With this being said, I do miss a ton of ViM features that aren't in Visual Studio. After what I learned today, I won't miss one - named buffers. To summarize the feature: if you need to preserve multiple items into the clipboard, do the following in command mode:
- select the text (Shift-V, Ctrl-V)
- pick a letter [A-Z] or a number [0-9] - say M
- type "My

To paste the contents of buffer 'M' in command mode, type: "Mp

The clipboard ring doesn't provide named buffers, but it remembers the last 15 items I copied, which is almost 90% of what I want. Here is how you use the feature:
1. Copy a selection using Ctrl-C (Copy).
2. Pressing Ctrl-V will paste the last item you copied.
3. Pressing Ctrl-Shift-V will also paste the last item in the clipboard. If you want to retrieve the second, or last item you inserted into the clipboard, simply keep pressing Ctrl-Shift-V to cycle through the items in the clipboard. Or just drag and drop any entry.

Q.E.D.

Tuesday, October 27, 2009

Sleep already Manoj!

In the last five weeks since my return from India, I feel like I have worked more than I did during the five months prior to my vacation. Each passing day brings with it a new challenge, a new hack is put in place, an old hack is reused, heads are scratched to find ways to not break existing users, and the entire team is getting progressively tired. There is still a lot to do, and though the next few weeks will be hell, there is light at the end of the tunnel. A few of the key moving pieces have fallen into place this past week, and if we meet our development targets for this week, we will be in even better shape to make our deadline. Aah, the week after we release is going to be a well-earned break from the madness. At Amazon though, such reprieves from a harried schedule are short (too short some would argue) - I don't underestimate my boss's ability to assign me to another under-staffed, high-visibility, high-risk task that needed to be done yesterday. I guess being busy is a virtue and a blessing in this economy.

It has been a little more than 17 months since I joined Amazon; forever the observer, here are some differences I have noticed between working at Microsoft and Amazon:

- Amazon adheres strictly to its dictum of "Frugality drives Innovation". The philosophy is so pervasive here that it has seemed to have an effect on people's behavioral patterns - they switch off lights, use CFL bulbs, are environmentally conscious and avoid waste wherever possible. Compare this to Microsoft where a casual walk through a corridor will reveal at least one office with multiple incandescent lamps glowing bright. Problem is, the line between frugality and inconvenience is a very thin one, and is often drawn wrong. For instance, getting a parking spot at Amazon requires jumping through so many hoops that I wonder whether the administrative overhead involved in reimbursing people for parking saves Amazon any money!

- The number of "friends" I have made at work can be counted on my fingers. Maybe it's where I am in life, maybe it's the people here, but I haven't formed a group of Amazonians I can hang out with after-hours. Most folks here go home to their other-half, go to the opera or the symphony or the theatre, usually have their activities planned weeks in advance... Such a sea change from my life on the East-side; gone are the days when we did things on the spur of the moment.

- Most Amazonians I have interacted with live on the West Side.

- The lack of a gym, like the Pro Club, affiliated with Amazon is a glaring omission from the benefits package. I miss The Pro - without it, I don't have social hour any more :(

- The average age of an Amazonian seems to be older than a Microsoftie's.

- After a certain amount of time passes, the politics and in-fighting is the same everywhere.

- I actually miss the Microsoft cafeterias. The soda - not so much, and the Starbucks coffee machines - not at all!

On to other things now. A few months ago, one of my closest friends left Seattle, a departure that left a gaping void in my life. You don't realize how dependent you have grown on a person until they are no longer around - even the most basic activity becomes more fun when you have someone to share it with. The abject loneliness struck me like a bolt of lightning during the first weeks upon my return from Bombay. I was sunk; my closest friends were more than a simple phone call away - some were married, others had left for new cities in new countries...

As I struggled to cope with the sudden changes in my surroundings, I got my first lucky break - a connection with a person I've known, if only in passing, since I was 16. Kapil and Prachie had moved to the Seattle area, their son Adi in tow, sometime this summer. New to the town, Kapil was looking for the same things as the weathered Seattle-local in me was: a person to trust, to play tennis with, to share stories from Bombay with. You know, reminisce about the good times, thereby making the present even more livable. Not a week has gone by since my return that we haven't hung out, and I haven't returned home the last two weekends because it's hard to tear myself away from Adi, the warmth of their home, and Prachie's bland-but-flavorful cooking. Unbeknown to them, these three are the accidental heroes of my recovery from the depths I had sunk to. I no longer feel alone here - I have people that care for me. It's one thing to feign positivity and happiness; the comfort of knowing that I have people has helped me find inner peace and happiness. Armed I feel, to take on the next challenge that comes my way.

Monday, October 26, 2009

The torrid Windows Mobile saga continues on

Trends in the Mobile Phone segment became required reading for me once I heard about Apple entering the fray. At one point I considered moving to the Windows Mobile team before better sense prevailed and my career took a different turn. To be fair, Microsoft used to be a contender in the Enterprise smartphone market a few years ago. Now that it isn't, it continues to shock me how Microsoft executives view the future of the segment, at how skewed their perceptions of user interactions with Mobile phones are, and how they continue to believe that Windows Mobile is what customers might want moving forward. Says Andrew Lees, Microsoft’s senior vice president for the Windows Mobile effort:
“Our value proposition is you can get your business and your consumer scenarios on the PC, and in a relevant way for you on the phone.”
Fact - there is no value proposition for WinMo customers presently.
So far, Microsoft has not been able to answer critics who say its operating system is old, slow and hard to use.

“Windows Mobile is simply dated, and that hasn’t changed in this release,” said Avi Greengart, research director for consumer devices at Current Analysis.

Indeed, a J. D. Power & Associates survey found that Windows Mobile had the lowest satisfaction rating among customers of any smartphone operating system. The iPhone has by far the most satisfying software, the study found. Android is a distant second, followed closely by BlackBerry’s operating system.

Windows Mobile scored below average on every attribute, said Kirk Parsons, director of the study, especially in ease of operation, speed and stability.
At least, Robbie Bach is willing to acknowledge that Microsoft should speed up its rate of innovation and think about customer scenarios more.
“You will see a speedy set of innovation for us in the next 6, 12, 24 months,” said Robert J. Bach, president of Microsoft’s entertainment and devices division at a news media event in New York to introduce a quick revision of the operating system called Windows Mobile 6.5. “Should we have picked up on the trends a little sooner? It’s hard not to say we should have,”he added.

Android’s supporters say that in contrast, Google’s software and the devices that run it are evolving very quickly.
I dare say, Windows Mobile needs an injection of Steven Sinofsky.

Wednesday, October 21, 2009

Safely using a SecureString in C# (don't convert it to a String)

There are a ton of examples online about how to use a C# SecureString object, but most of them have 1 key bug in them that renders the use of SecureString redundant - the examples convert the SecureString into a System.String object!

For those who don't know what a SecureString is, it's secure, it's safe and it should be used to protect resources like passwords, secret keys, etc. After some digging, I found a way to reduce the SecureString attack surface as much as possible. Here's how to generate an RFC-2104 compliant signature (used by AWS services like S3) with a SecureString:
public static string Sign(string data, System.Security.SecureString key, KeyedHashAlgorithm algorithm)
{
    // pointer to hold unmanaged reference to SecureString instance
    IntPtr bstr = IntPtr.Zero;
    char[] charArray = new char[key.Length];
    try 
    {   
        // Marshal SecureString into byte array
        bstr = Marshal.SecureStringToBSTR(key);
        Marshal.Copy(bstr, charArray, 0, charArray.Length);
        algorithm.Key = Encoding.UTF8.GetBytes(charArray);
        return Convert.ToBase64String(algorithm.ComputeHash(
            Encoding.UTF8.GetBytes(data.ToCharArray()))
            );  
    }   
    finally
    {   
        // Make sure that the clear text data is zeroed out 
        algorithm.Clear();
        Array.Clear(charArray, 0, charArray.Length);
        Marshal.ZeroFreeBSTR(bstr);
    }   
}

Wednesday, October 14, 2009

Been a while

A lot has transpired since the last time I wrote a real blog post. Yes it's true, I am bitten by the twitter bug! It is infinitely easier to live in the moment, to observe rather than reflect, to react rather than think. Even when I did want to write, my surroundings conspired against my best wishes and left me with no real time or peace of mind to pen my thoughts. It turns out that unless I take the time to void my thoughts, they will continue to occupy my mind; there is no notion of free time - it is all spoken for.

Approximately a month ago, I grudgingly returned back to Seattle from a three week sojourn in Bombay. It was hard to come back this time, especially after having spent time in the throes of family. In an odd twist, no other entity can make you realize how lonely your existence is more than your own family can. Selfish as it may sound, there is something deeply comforting about the fact that someone is either waiting for you to get home or you are waiting for someone to come home to you. I now understand the compulsion people feel to start a family, to get a dog, to live with room-mates. Like cocaine addiction, this sense of comfort is uplifting yet fleeting; once you acquire it, you chase the high forever.

Often times we go on vacation and come back relaxed, with no other real dividend earned. This trip to India, relaxing as it was, yielded an unexpected bonus - I experienced what a parent must feel when they see their child grow up into an adult. For many years now, Nikhil has been a free agent; it has been hard to pin him down and inspire him to do anything of real import. The Nikhil I saw this time around was a changed person. He took a huge responsibility upon himself, he shepherded a store from conception to completion before my very eyes, vetoed decisions that he believed weren't in the best interests of the brand at large, and managed finances to the best of his abilities. This, for a guy who couldn't concentrate on anything work-related for more than two hours, was a volte face! My younger brother had finally stepped up to his responsibilities and taken his rightful place among the league of men. I have no doubts that he will be Extraordinary.

Since my return, I have plunged headlong into the sea of work yet to be accomplished. With a new product release around the corner, work is proving to be more than just a distraction from the bigger problems I have to eventually encounter. If I am not vigilant, work will consume every waking moment, even percolate into the nether hours thereby disrupting my already fragile circadian rhythms. I need to take pause, make the most of my time at work and strive for balance. Wish me well, for I will definitely need all the blessings I can muster...

Monday, October 05, 2009

Transferring large files > 512 MB using C# HttpWebRequest

When transferring large files over the network using C#, there is a good chance that your application will be thwarted by either:
- System.IO.Exception
- System.Net.WebException

Depending on the order in which you catch exceptions, you might spend a good deal of time debugging the root cause of the problem. In my case, I was trying to send a 4GB file over the wire; every time I tried, the upload would fail with the message:

System.Net.WebException: The request was aborted: The request was canceled.
System.IO.IOException: Cannot clos e stream until all bytes are written.

After a lot of debugging and speculation, the actual cause of the exception was not related to my use of Read/Write with the Stream(s) I chose for the operations. The issue was with the way the HttpWebRequest was configured, in particular, the timeout values associated with the request.

Refer the Properties section of HttpWebRequest@MSDN and look at the description for ReadWriteTimeout. The default value for this timeout, 300 seconds, was too low for the amount of data being transferred, resulting in the write being aborted prematurely. The only consequence of such an action is the exception I stated earlier. The fix: simple - increase the timeout to a reasonable value; our application has this set to 10 minutes.