I’m working on a project where we use Deployment Projects to deploy our public application. We’re still in beta phase so we don’t have a huge number of releases under our belt yet but so far things have been going pretty well (well, at least since we’ve gotten past the initial hurdles in getting our first installer out). Well, something new has jumped up and surprised us. And honestly, now that I understand it, I’m shocked that we’ve not seen it in any of our last 5ish releases.
So here’s the context: We had a prior version of our app installed and we wanted to upgrade from that version to the newest version. We have the installer uninstall the old version (for this part hopefully by now you know that it’s good and important for all assemblies in the installer to be properly versioned and at or above 1.0). This is done by the freebie stuff and the Uninstall events that get fired within our Installer Class/custom action to manage a few things, including our databases. Next the new version gets installed (again by the freebie stuff and custom actions). The last thing our custom action class does is upgrades our databases from the older verson to the newer version. This is how we’ve done things for the past 5ish versions and everything has worked just fine and dandy as long as we’re on the ball with versioning our assemblies correctly.
Well, this version I updated all of our installer files just as I had done with the previous versions and when I went to test it, I was surprised. For some reason the install seemed to work fine EXCEPT for our custom actions. To make a long story short, what was happening was that our custom actions from our previous version were getting executed when the installer was installing the newer version!! So obviously since our databases are maintained by these custom actions, the problems were pretty obvious from the beginning.
I ultimately found this article online which points to this KB article of Microsoft’s (EDIT: this is the VS2005 version of the bug, I previously linked the VS2003 version of the bug) and it turns out that this is a bug in Visual Studio 2005 that was posted in August of 2004. The short version of the problem is with the assembly name for our custom action. When Windows Installer loads CustomAction v3 for the uninstall and attempts to load CustomAction v4 for the new install, it unreliably does not load v4 because it sees it already has CustomAction loaded but forgets to care about what version it is. So then when the new version of the app fires the events for our DLL, they get handled by the old code and not by the new code.
There are two things to be aware of with this scenario to fix it. The first is an end-user work-around in case you need such a thing for an installation that you might have already made public. If the end-user runs your installer and this happens, running the installer again and selecting “Repair” will then run the correct version of the DLLs. Now this may or may not help you, depending on your scenario. Luckily for us, this is an acceptable work-around without trashing any data because of our architecture around updating our client databases with each release. Now the second thing to be aware of is a more permanent fix. If you change the Assembly name for your custom action to be unique with each deployment, this will allow you to prevent this from happening again. So instead of my custom action’s assembly name being “Company.Project.Installer.CustomAction” it is now “Company.Project.Installer.CustomAction_v18.104.22.168” and of course I change this with each release.
Good luck and I hope you find this problem and solution before wasting hours of time like I did!