Question

I have an App I have updated with some .Net4 assemblies, including the custom actions .dll that runs when the app is going to be uninstalled. The App was initially installed with .Net 3.5 and it requires some custom actions when installing and uninstalling.

The problem is that now when uninstalling the .dll of the custom actions have changed to its .Net 4 version and I'm getting a System.BadImageFormatException: Could not load file or assembly 'X' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded. File name: 'X'

Does anyone knows a way to tell the uninstaller to start the process with .Net 4 instead of calling .Net 3.5 to load the custom actions Dll? Where does this uninstall information is stored for each product? and how?

Was it helpful?

Solution 3

After a long research I found a way to solve the issue. I made a version of the application on .Net 4 and generated the installer. Installed it and then compared the .msi file the application saves on the C:\Windows\Installer folder with the previous version of the same file but with .Net 3.5 ( original installation). Then open both files with Orcas and changed some property values and a couple of binary files on the .Net 3.5 msi file from the new .Net 4 msi file.
Now when I make an update of single files in the App to a .Net 4 version of them( so the app runs under .Net 4) I also need to change that uninstall .msi file located under c:\Windows\Installer and then when uninstalling the Windows Installer will invoke .Net 4 to do the custom actions instead of .Net 3.5 which was the original build when the app was installed.

Here is a script that automates the process and no need to use orcas, just pass the msi file to change and the two necessary Dll ( which I extracted from the msi of the .Net 4 version).

var installer=new ActiveXObject("WindowsInstaller.Installer");
var db;
var msiOpenDatabaseModeTransact = 1;
var msiFile = WScript.Arguments.Item(0);
var installbuildfile = WScript.Arguments.Item(1);
var auxDllFile = WScript.Arguments.Item(2);
database = installer.OpenDatabase(msiFile, msiOpenDatabaseModeTransact);

    var view = database.OpenView("SELECT Name,Data FROM Binary");
    view.Execute();
    var rec;
    for (rec = view.Fetch(); rec != null; rec = view.Fetch()) {
        WScript.echo("Current SmartUpdater.exe version is: "+rec.StringData(1)); 
        if (rec.StringData(1) == "InstallUtil") {
            rec.SetStream(2, installbuildfile);
            view.Modify(2, rec)
            WScript.echo("Changed: " + rec.StringData(1)); 
        }
        if (rec.StringData(1) == "MSVBDPCADLL") {
            rec.SetStream(2, auxDllFile);
            view.Modify(2, rec)
            WScript.echo("Changed: " + rec.StringData(1)); 
        }
    }
    view.Close();
    view = database.OpenView("UPDATE Property SET Value='v4.0' WHERE Property='VSDFrameworkVersion'");
    view.Execute();
    view.Close();

database.Commit();

The InstallUtil dll file can be found on the .Net directory under c:\Windows for the 4.0 version, the second one named MSVBDPCADLL is still a mistery for me, but I could extract it from the MSI of the generated .Net 4 ( there can be differences for 32 and 64 versions, probably you will need to extract the different versions of the Dlls)

OTHER TIPS

Hello To target a specific version of the .NET framework for an executable named app.exe, you can put those lines :

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0.30319"/>
  </startup>
</configuration>

to a file named app.exe.config close to the executable. If the file already exists, just merge the two xmls (EDIT : I put 'v4.0.30319' because this is the version that I have on my computer, but you should put the one you have, look at %WINDIR%\Microsoft.NET\Framework or %WINDIR%\Microsoft.NET\Framework64 to get it) .

Maybe you don't know the name of the executable that uninstall your software. In that case, you may try to use process explorer to find it (http://www.windowsitpro.com/article/utilities/find-the-source-of-an-error-message.aspx).

But beware : doing this will change the .NET FX target of all runs with the same process, hence (maybe) change the behaviour of all uninstall done with this uninstaller !

What version of windows installer are you using? I can't say for sure, but I wonder if you are using an older version of the installer that wants to use the 3.5 framework.

To check, look at the Properties for the setup project. Click "Prerequisites", and scroll to the bottom of the dialog. Check the version you want to use for the install process.

Honestly, I have never had/noticed this problem, but I wonder if using the newer Windows Installer would fix it.

Hello, SO!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top