[wix-users] Custom Action Files

Brian Enderle brianke at gmail.com
Fri Dec 11 09:35:22 PST 2015

I have an installer with a CusotmAction that has been built and deployed
corectly in the past using WiX 3.9.  I recently updated to WiX3.10 and I am
now getting errors during installation when the custom action tries to run:

System.Reflection.TargetInvocationException: Exception has been thrown by
the target of an invocation. ---> System.IO.DirectoryNotFoundException:
Could not find a part of the path
'C:\ProgramData\MyCompany\MyProduct\InstallScripts\01_Create Database.sql'.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess
access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize,
FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean
bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
access, FileShare share)
   at System.IO.File.Open(String path, FileMode mode, FileAccess access,
FileShare share)
   at CustomActions.CustomActions.FileContentsToString(FileInfo file)
   at CustomActions.CustomActions.SQL_Step1(Session session, Database
   at CustomActions.CustomActions.ExecuteSQLCustomAction(Session session)
. . . .

The method executed for this CustomAction is:

        private static ActionResult SQL_Step1(Session session,
Models.Database dbInfo)
            //MessageBox.Show("Executing Custom Action Step 1", "Step 1");

            // 01_Create Database.sql
            FileInfo _file = new
FileInfo(session.CustomActionData["Directory"] + "01_Create Database.sql");
            String _script = FileContentsToString(_file);
            session.Log(String.Format("*** dbInfo: {0}, {1}",
dbInfo.ServerName, dbInfo.Username));
            session.Log("*** Filename: " + _file.Name + "\n    Contents:\n"
+ _script);
            session.Log("*** Executing " + _file.FullName);

                // Execute the SQL command script
                using (SQLClass _sql = new SQLClass(dbInfo))
                    session.Log("SQL Connection established to " +
                    _sql.ExecuteSqlScript(_script, null, false);
            catch (Exception ex)
                MessageBox.Show("Custom Action Step 1: \n" +
ex.GetBaseException().Message, "Installation Error", MessageBoxButtons.OK,
                session.Log("****ERROR in custom action SQL_Step1,
executing '{0}': {1}", _file.Name, ex.GetBaseException().Message);
                return ActionResult.Failure;

            return ActionResult.Success;

The files are stored in the CustomActions project, in a folder called
'InstallScripts', with a Build Action of Content/Do no copy.  I also tried
setting this to Resource but am getting the same error.

Has something changed in 3.10 to now break this?


If you can't explain it simply, you don't understand it well enough.  -
Albert Einstein

More information about the wix-users mailing list