Invalid dll action. Installer shows error: Wizard ended prematurely

I am using a dll to copy one directory to another as part of wix. Since in the test program I am using the following code, which works fine with the console application .

Backup.dll

namespace WiXTutorial.Samples
{
    using System;
    using System.Collections.Generic;
    using System.IO;
    using Microsoft.Deployment.WindowsInstaller;

    public class SampleCheckPID
    {
        [CustomAction]
        public static ActionResult Backup(Session session)
        {
            DirectoryCopy(@"D:\share", @"D:\sharecopy", true);
            return ActionResult.Success;
        }

        private static void DirectoryCopy(
            string sourceDirName, string destDirName, bool copySubDirs)
        {
            DirectoryInfo dir = new DirectoryInfo(sourceDirName);
            DirectoryInfo[] dirs = dir.GetDirectories();

            // If the source directory does not exist, throw an exception.
            if (!dir.Exists)
            {
                throw new DirectoryNotFoundException(
                    "Source directory does not exist or could not be found: "
                    + sourceDirName);
            }

            // If the destination directory does not exist, create it.
            if (!Directory.Exists(destDirName))
            {
                Directory.CreateDirectory(destDirName);
            }


            // Get the file contents of the directory to copy.
            FileInfo[] files = dir.GetFiles();

            foreach (FileInfo file in files)
            {
                // Create the path to the new copy of the file.
                string temppath = Path.Combine(destDirName, file.Name);

                // Copy the file.
                file.CopyTo(temppath, false);
            }

            // If copySubDirs is true, copy the subdirectories.
            if (copySubDirs)
            {

                foreach (DirectoryInfo subdir in dirs)
                {
                    // Create the subdirectory.
                    string temppath = Path.Combine(destDirName, subdir.Name);

                    // Copy the subdirectories.
                    DirectoryCopy(subdir.FullName, temppath, copySubDirs);
                }
            }
        }
    }
}

      

Product.wxs

<CustomAction Id='Backup' DllEntry='Backup' BinaryKey='CheckPID' Execute='immediate' Return='check'  />

<InstallExecuteSequence>
    <Custom Action='Backup' After='InstallFiles' />
</InstallExecuteSequence>


<Binary Id='CheckPID' SourceFile='D:\Nirvana\Installer\Backup\Backup\bin\Debug\Backup.dll' />

      

Above the line of code builds fine as mentioned in the link - http://wixtoolset.org/documentation/manual/v3/wixdev/extensions/authoring_custom_actions.html

and

- https://www.firegiant.com/wix/tutorial/events-and-actions/how-to-manage/

But when I install the application, it shows the error: Wizard finished prematurely

enter image description here

This is my log exit

Error: could not load custom action class WiXTutorial.Samples.SampleCheckPID from assembly: CheckPID System.BadImageFormatException: 
Could not load file or assembly 'CheckPID' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded. 
File name: 'CheckPID' at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) 
    at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) at System.AppDomain.Load(String assemblyString) 
    at Microsoft.Deployment.WindowsInstaller.CustomActionProxy.GetCustomActionMethod(Session session, String assemblyName, String className, String methodName)

WRN: Assembly binding logging is turned OFF. To enable assembly bind failure logging, set the registry value (DWORD) to 1. 
Note: There is some performance penalty associated with assembly bind failure logging. To turn this feature off, remove the registry value .

CustomAction Backup returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox) 
Action ended 17:01:54: Backup. Return value 3. MSI (s) (04:BC) 
[17:01:54:356]: User policy value 'DisableRollback' is 0 MSI (s) (04:BC) 
[17:01:54:356]: Machine policy value 'DisableRollback' is 0 MSI (s) (04:BC) 
[17:01:54:357]: Calling SRSetRestorePoint API. dwRestorePtType: 13, dwEventType: 103, llSequenceNumber: 342, szDescription: "". MSI (s) (04:BC) 
[17:01:54:357]: The call to SRSetRestorePoint API succeeded. Returned status: 0. MSI (s) (04:BC) 
[17:01:54:357]: Unlocking Server Action ended 17:01:54: INSTALL. Return value 3.

      

+3


source to share


2 answers


Your log has this error message:

This assembly was built using a runtime newer than the currently loaded runtime and cannot be loaded.

One possible reason for this is an assembly built with .NET 4 and a loaded runtime with .NET 2 for example. Below is the question and answer:



This assembly is built using a runtime newer than the currently loaded runtime and cannot be loaded

Make sure you are using the correct version of the compiler for building the WiX package (if from the command line to a * .sln file) and custom actions.

0


source


If you create a project for this custom activity using the template provided by WixToolset, it will generate two dlls when you create the project:

D: \ Nirvana \ Installer \ Backup \ Backup \ bin \ Debug \ Backup.dll D: \ Nirvana \ Installer \ Backup \ Backup \ bin \ Debug \ Backup.CA.dll



the second is the one to be referenced:

<Binary Id='CheckPID' SourceFile='D:\Nirvana\Installer\Backup\Backup\bin\Debug\Backup.CA.dll' />

      

0


source







All Articles