Category Archives: tip

WIX 3.5 – error LGHT0001: Unable to load DLL ‘winterop.dll’

It has been a while, but here I am again ;) … I am currently working on an old Visual Studio 2005 solution. This bugger used to be built by a build server, but that one died about a year ago. Since some bugs really needed fixing, I decided that I would build the project myself for the moment.

Problem was that the solution uses WIX 3.0, and I have WIX 3.5 installed on my machine. After converting the WIX projects I expected the project to build without any problems. Unfortunately, however, WIX crashes with the following error: error LGHT0001: Unable to load DLL ‘winterop.dll’: The specified module could not be found. (Exception from HRESULT: 0x8007007E).

After some searching on the web I found a post (not entirely my problem) with the searched solution: add the installation path of WIX to the Path variable. After this workaround everything works like a charm. Hope this helps you too ;) !

Happy coding!

Clean and minified Javascript

It has been a while since I last posted a technical post. I’m sorry, but I am too busy enjoying my work to keep you posted as much as I should.

Just a few days ago I was playing around with YSlow and PageSpeed, two add-ons on Firefox. Both stated my Javascript files were 1) to many and 2) not at all at minimum size.

Searching for an automated way of cleaning up and minifying my Javascript files, I bumped in on JSMin, a Javascript minifier that can be downloaded in C#. Do you hear the term HttpModule in your head already as I did?

When you try to implement JSMin, do consider the fact that your Javascript files will be stripped really rigorous: some of my files did not work anymore after minifying. The reason for this is that Javascript gives you the opportunity to write bad code. To prevent myself from writing rubbish Javascript files that fall apart using JSMin, I now use ‘the tool that hurts feelings’, JSLint. It hints you about bad code and, when obliged to, prevents you from failure when using JSMin afterwards ;)

Lucky coding :) !

Move IMAP Personal Folder File in Outlook 2007

This post is kind-of off-topic concerning my main blog topic area, but 1) it has been a while since my last post and 2) the topic has caused me a headache, so I decided to blog it.

Besides my own mailbox, hosted in Exchange, I often load other IMAP mailboxes in the same Outlook profile. IMAP tries to work in the same way as Exchange (it leaves all messages on the server and – if properly configured – also stores sent items there). So far, so good.

Here comes the nasty part: reading this post, you probably faced the same problem as I did. Moving the data file from your personal folder to another folder is not just as easy as when working with a POP3 mailbox – when moving, Outlook just keeps generating a new PST file when you delete it. Besides, there is no option such as ‘move mailbox’.

Just a note before you read on: you cannot reload an ‘IMAP backup PST file’. If you are trying to do anything like that, just stop since you will fail reaching your goal. Therefore, backing up IMAP folders does not make any sense.

After the misery from the previous paragraph I can give you some relief: it is not hard to move the PST file. It’s just the ‘workflow’ that matters:

  1. Close Outlook.
  2. Open the Mail item in Control Panel.
  3. Open the profile to work on and go to its data file(s).
  4. Locate the original data file location.
  5. Let the data file window stay open!
  6. Move the PST file. Don’t rename or point to another file – silly, yes I know – or an empty PST file will definitely be created in the original folder.
  7. Double click the data file in the window you should have left open. It shows you an error message and after clicking that one away, you can select the new location of your mailbox.
  8. Close all mail windows.
  9. Open Outlook.
  10. [Check the original PST file folder for possible newly created mailbox files - if so, you made a mistake following my guidelines ;) .]
  11. You’re done!


The using statement and XmlReader.Create

Are you also fond of using the using statement (e.g. when dealing with streams)? I am, since it kind-of guarantees me that streams are closed when I think they should be closed, even if I do not specify the Dispose() command. You probably noticed the ‘kind-of guarantee’ part. You are right, this is not always the case. It took me a while to find out the the following is not going to work as smooth as expected:

using (var reader = XmlReader.Create(File.Open(fileName, FileMode.Open)))
    { ... }

You probably wonder what’s the problem of the code printed above. I don’t see it too, however, I know there is a problem related to this code. The problem lies in the Create overload used in the example code. It uses default XmlReaderSettings. Unfortunately, this settings do not include having the CloseInput property set to true. You can do the math: no closed file at all! That’s a guarantee for having troubles on the file ‘being in use already’.

The solution to this problem is quite simple:

using (XmlReader reader = XmlReader.Create(File.Open(path, FileMode.Open),
         new XmlReaderSettings { CloseInput = true })) { ... }

How can we call this? A ‘bug’? No, at least not technically spoken. Since the XmlReader creates the stream, it should close it too. The case is, you should not expext it knowing the using statement as most people know it (fail-proofing your code). Since I know this, I am a little bit scared about using using statements without calling the stream’s constructor. You can do so, but be sure it does what you expect it to do… In my opinion, the using statement still remains very helpful, please I do not consider it being as perfect as I thought it to be for years ;)

Calculate age (for instance, on reference data)

Now and then, I have to calculate ages (for instance, on a reference date). The method to calculate ages in .NET is pretty simple, although it can be ‘a pain in the ass’ to find out how simple it should have been :) … Enjoy the code :) !

public static class DateTimeHelper
    public static int CalculateAge(DateTime birthday)
        return CalculateAge(DateTime.Now, birthday);

    public static int CalculateAge(DateTime referenceDate, DateTime birthday)
        // calculate age in years on the given reference date.
        var comparisonDate = new DateTime(birthday.Year, referenceDate.Month, referenceDate.Day);

        return (comparisonDate.Date < birthday.Date)
                      ? referenceDate.Year - birthday.Year - 1
                      : referenceDate.Year - birthday.Year;