Ezi
Ezi

Reputation: 2210

WiX Custom Action Ends Prematurely

There are multiple questions on that topic, I tried all the solutions but nothing worked for me.

The problem is that it 'does' work on machines with visual studio installed, but does not work on other pc's.. making it very hard to debug.

The custom action code is:

[CustomAction]
public static ActionResult EnumerateSqlServers(Session session)
{
    MessageBox.Show("start EnumerateSQLServers"); // the message is not showing.
    ActionResult result;
    DataTable dt = SmoApplication.EnumAvailableSqlServers(false);
    DataRow[] rows = dt.Select(string.Empty);//, "IsLocal desc, Name asc");
    result = EnumSqlServersIntoComboBox(session, rows);
    return result;
}

The log file shows:

MSI (c) (2C:1C) [11:16:42:338]: Doing action: EnumerateSqlServersAction
Action 11:16:42: EnumerateSqlServersAction. 
Action start 11:16:42: EnumerateSqlServersAction.
MSI (c) (2C:34) [11:16:42:385]: Invoking remote custom action. DLL: C:\Users\Test\AppData\Local\Temp\MSI9328.tmp, Entrypoint: EnumerateSqlServers
MSI (c) (2C:E8) [11:16:42:385]: Cloaking enabled.
MSI (c) (2C:E8) [11:16:42:385]: Attempting to enable all disabled privileges before calling Install on Server
MSI (c) (2C:E8) [11:16:42:385]: Connected to service for CA interface.
Action ended 11:16:42: EnumerateSqlServersAction. Return value 3.
DEBUG: Error 2896:  Executing action EnumerateSqlServersAction failed.
The installer has encountered an unexpected error installing this package. This may indicate a problem with this package. The error code is 2896. The arguments are: EnumerateSqlServersAction, , 
Action ended 11:16:42: WelcomeDlg. Return value 3.
MSI (c) (2C:44) [11:16:42:635]: Doing action: FatalError
Action 11:16:42: FatalError. 
Action start 11:16:42: FatalError.
Action 11:16:42: FatalError. Dialog created
Action ended 11:16:43: FatalError. Return value 2.
Action ended 11:16:43: INSTALL. Return value 3.
MSI (c) (2C:44) [11:16:43:370]: Destroying RemoteAPI object.
MSI (c) (2C:E8) [11:16:43:385]: Custom Action Manager thread ending.

I did try a empty action like this:

 [CustomAction]
        public static ActionResult CustomAction1(Session session)
        {
            MessageBox.Show("");
            return ActionResult.Success;
        }

that action works! it shows an empty message box.

EDIT: After a lot of testing, I found that the problem is with enumSQLServer when I comment this line it works.

SmoApplication.EnumAvailableSqlServers(false);

Upvotes: 1

Views: 1668

Answers (3)

Kevin Aung
Kevin Aung

Reputation: 832

In my case, this was happening on the install AND uninstall.

What we're doing is encrypting the connection string that was being passed in as a parameter.

Install

This fails because I don't have access to the installed config file which we're still working out. I wish WiX was a little easier to use or had better documentation.

Uninstall

Because we didn't have any conditions for the Custom Action, it was also running during uninstall and failing when attempting to load the config file that doesn't exist anymore.

Solution: Use NOT Installed AND NOT REMOVE. How to execute custom action only in install (not uninstall)

Upvotes: 0

Did you already try to run your setup with elevated rights (right click on the setup and select "Run as administrator")?

SmoApplication.EnumAvailableSqlServers(false) needs elevated rights as far as I know.

Also check your definition of your custom action in your Product node within your .wxs file.

Following definition should work:

<CustomAction Id="EnumerateSqlServers" BinaryKey="YOUR BINARY KEY" DllEntry="EnumerateSqlServers" Execute="immediate" Return="check"/>

Also try the following for testing purposes:

<InstallUISequence> <Custom Action="EnumerateSqlServers" Before="ExecuteAction" Overridable="yes">NOT Installed</Custom> </InstallUISequence>

Upvotes: 0

Christopher Painter
Christopher Painter

Reputation: 55581

Log the installer using verbose (/l*v) settings. I expect to see a lot more including a .NET error stack trace. You are likely missing a dependency that's on the visual studio machine but not your clean test machine.

The most likely missing dependency is Microsoft.SqlServer.Smo.dll. In your custom action project check to see if this reference is set to CopyLocal = true and set it if it is not.

Upvotes: 2

Related Questions