[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.setup

Gracefully fail an installation

stephajn

2/16/2007 6:32:00 PM

I've done all kinds of google searching on this topic, and everyone
seems to say the same thing:

In a Visual Studio Setup package, if I want to fail an installation
based on something found in my custom action code, then I just throw
an InstallException and the runtime will be informed that it must
rollback. The only problem here is that the error message displayed to
the user contains information they don't need to see like the method
name being called, etc.

If I'm going to rollback, I want to be able to display a message box
of my liking to the user in a way they'll understand. For example,
let's say that I'm installing an application that has a dependency on
Internet Explorer 6 or higher.

I could throw an install exception like this:

throw new InstallException("This application requires you to have
Internet Explorer 6 or higher installed.");

But the display that comes up shows some nastiness in it regarding the
method that threw it and so on. What I want to do is this:

catch (InstallException instEx)
{
MessageBox.Show(instEx.Message, "Installation Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
Rollback(savedState);
}

However, what winds up happening is that the Rollback method winds up
throwing its own exception about how the savedState dictionary does
not contain the expected values. So now what am I supposed to do
exactly? Do I need to change the savedState dictionary in some way?

Thanks for any help anyone can give on this.
Stephajn

1 Answer

Phil Wilson

2/22/2007 8:49:00 PM

0

The general issue here is that you're using Visual Studio setups and managed
code custom actions. VS setups are not fully featured enough to do what you
want when compared with the other 20 or so tools out there that build MSI
setups. A type 19 custom action is one of the ways you can cause a graceful
termination, but VS setups don't do them. Managed code custom actions have a
lot of infrastructure involving a shim C++ Dll that explicitly loads the CLR
to run your managaed code because MSI does not natively support managed code
custom actions, so you're working within that framework where throwing
InstallException is the way to indicate an error.

Having said that, throwing an InstallException for the wrong version of IE
is rather late in the game. That's what LaunchConditions are for, so if that
IE example is a real one, I'd create a Search Target System that did a file
search for (probably) shdocvw.dll in [SystemFolder] with a minimum version
of 6.0.0, and use the property from the search as a launch condition with
the message "You need at least IE 6.0".

--
Phil Wilson
[Microsoft MVP Windows Installer]
<stephajn@gmail.com> wrote in message
news:1171650704.830917.126730@h3g2000cwc.googlegroups.com...
> I've done all kinds of google searching on this topic, and everyone
> seems to say the same thing:
>
> In a Visual Studio Setup package, if I want to fail an installation
> based on something found in my custom action code, then I just throw
> an InstallException and the runtime will be informed that it must
> rollback. The only problem here is that the error message displayed to
> the user contains information they don't need to see like the method
> name being called, etc.
>
> If I'm going to rollback, I want to be able to display a message box
> of my liking to the user in a way they'll understand. For example,
> let's say that I'm installing an application that has a dependency on
> Internet Explorer 6 or higher.
>
> I could throw an install exception like this:
>
> throw new InstallException("This application requires you to have
> Internet Explorer 6 or higher installed.");
>
> But the display that comes up shows some nastiness in it regarding the
> method that threw it and so on. What I want to do is this:
>
> catch (InstallException instEx)
> {
> MessageBox.Show(instEx.Message, "Installation Error",
> MessageBoxButtons.OK, MessageBoxIcon.Error);
> Rollback(savedState);
> }
>
> However, what winds up happening is that the Rollback method winds up
> throwing its own exception about how the savedState dictionary does
> not contain the expected values. So now what am I supposed to do
> exactly? Do I need to change the savedState dictionary in some way?
>
> Thanks for any help anyone can give on this.
> Stephajn
>