I am using dll for copying one directory to another as a part of wix . So as a test program I am using following code that works fine with 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 code builds fine as refrenced by 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 application it shows error : Wizard ended prematurely
This is my log output
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.
In your log there is this error message:
This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
One possible cause of this is your assembly being built with .NET 4 and the loaded runtime with .NET 2, for example. The question and answer below have more information about it:
"This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded"
Make sure you are using the correct version of the compiler to build both the WiX package (if from command prompt to a *.sln file) and the custom actions.