views:

26

answers:

1

I have a Windows installer project which includes a custom action. This custom action uses SMO to configure a databse. The installer project is .Net 4. When executing the custom action, I get the following error:

    Mixed mode assembly is built against version 'v2.0.50727' of the runtime 
and cannot be loaded in the 4.0 runtime without additional configuration information.

I could run the database update code in a separate executable or rewrite the custom action so SMO is not used but I'd rather keep the code as it is if possible.

I know how to fix this in console and Winforms apps by adding the following to the app.config file.

<?xml version="1.0"?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>

The question is how on earth do I do this or something similar with an installer project? I still get this issue when all the referenced assemblies in the custom action are frame work 2 so it must be caused by the MSI itself which is .net4 according to the Fusion Log Viewer.

A: 

In the end I decided to launch a concole app from the installer's custom action to do the necessary updates to the databse. It works well

the code is to call the console app from the installer is :

public enum ReturnCode
{   
    Error = -1,
    Updated = 0,
    UpdateNotRequired = 1,
    ServerNotAvailable = 2,
    DatabaseNotAvailable = 3
}

private int UpdateSchema(string installationPath)
{
    const string exeName = @"SchemaUpdater";

    string executablePath = Path.Combine(installationPath, exeName);

    LogModule.Log_NewLogEntry("Starting Schema Updater");

    var myProcessStartInfo = new ProcessStartInfo(executablePath);
    myProcessStartInfo.UseShellExecute = false;
    myProcessStartInfo.CreateNoWindow = true;

    Process process = Process.Start(myProcessStartInfo);
    process.WaitForExit();

    int exitCode = process.ExitCode;

    LogModule.Log_NewLogEntry(string.Format("SchemaUpdate returned {0}", exitCode));

    return exitCode;
}

public override void Install(IDictionary stateSaver)
{
    string installationPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

    int dbUpdaterReturnVal = UpdateSchema(installationPath);

    if (dbUpdaterReturnVal < 0)
    {
        throw new Exception("Schema Update returned with an error");
    }

    if (dbUpdaterReturnVal == (int)ReturnCode.ServerNotAvailable)
    {
        throw new Exception("SqlServer Not available. Aborting Install");
    }

   base.Install(stateSaver);
}
Dominic