none
Windows Installer from .Net 2.0 Custom Action to .Net 4.0 Custom Action - BadImageFormatException

    Question

  • I'm having a problem with an application that I recently upgraded from .Net 2.0 to .Net 4.0. During installation, the custom action starts to execute and throws an error.

    === Logging started: 9/30/2011 2:34:09 === Error 1001. Error 1001. Exception occurred while initializing the installation: System.BadImageFormatException: Could not load file or assembly 'file:///C:\Program Files\MyPath\MyCustomAction.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.. === Logging stopped: 9/30/2011 2:34:30 ===

    Note that should I uninstall the old version of the application first, then install the new version of the application, the installation succeeds without error.

    The only thing I can guess is that the .Net 2.0 custom action is failing to be loaded by Windows Installer as it's not the same .Net 4.0 framework as used by the latest version of my application. Has anyone run into this?

     

    Additional Notes:

    Since I install from the MSI, the pre-reqs are not being evaluated (at least last I knew about windows installers). If I click on my setup project, I go to the Launch Conditions Icon, and under Requirements on Target Machine I have the Search Target Machine node that is empty (has nothing in it), and I have the Launch Conditions node which has 1 item under it. .Net Framework. The properties of that .Net Framework Launch Condition is: 

    Name: ".Net Framework"

    InstallURL: "go.microsoft.com/fwlink/?LinkId=76617";

    Message: "[VSDNETMSG]"

    Version: ".Net Framework 4 Client Profile".

    Under Advanced Compile Options of my Custom Action, I have "Generate serialization assemblies = Auto", "Target CP = AnyCPU", "Target framework (all configurations) = .Net Framework 4 Client Profile


    All custom libraries in my updated solution are also using the same .Net 4. Client Profile framework with the same Advanced Compile Options set.

    The installer is set to run against X86 platforms.

    I then removed the custom action, attempted to upgrade, and got a new error: "Error 1001. An exception occurred while uninstalling. This exception will be ignored and the uninstall will continue. However, the application might not be fully uninstalled after the uninstall is complete. --> Could not load file or assembly 'MyAssembly.NameSpace, Version=1.2.3.0, culture=neutral, ...".

    I guess for whatever reason, during an Upgrade, the Windows Installer is trying to load my old assemblies with the .Net 4.0 framework.  Is there a way to make the uninstall portion of this installation process uninstall my old version while targeting .Net 2.0 and then install targeting .Net 4.0?


    Rob
    Friday, September 30, 2011 8:30 PM

All replies

  • Hi Rob,

    Welcome to the MSDN Forum.

    As I understand, the error 1001 is can not load the assemblies. Maybe some of the dlls in your projects can not be load at the runtime. You will need to rebuild it and make sure it is capable to run in the os. On the other hand, the conditions is not right.

    the Versions shows .Net Framework 4 Client Profile, but the InstallURL is the .Net Framework 3.5. you will need to re-select the prerequsites and select the right version framwork for your applications.

    With all the tests, please remove the old versions first.

    Best Regards


    Neddy Ren [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, October 03, 2011 9:26 AM
  • I'm not following.

    You are correct that the install URL looks weird here, but the Launch Condition is set to the .Net 4.0 Client Profile framework.

    This issue is only occuring during an upgrade process.  It's an installer issue.  I can execute the application just fine and install it just fine by performing a clean installation as opposed to upgrading an installation.

    The problem is the installer is trying to load the .Net 2.0 assemblies during installation.  It seems like the installer is only supporting .Net 4.0.  This seems like a nasty Windows Installer bug that I wish Microsoft would address...


    Rob
    Monday, October 03, 2011 4:29 PM
  • Hi Rob,

    As I tested, I think maybe you have use some features of .Net Framework 3.5 in your projects and in the new projects after you upgrade it to .Net Framework 4.0, you deploy it and add the Prerequisites, such as .Net 4.0, or you add the .Net Framework by your cusom adding. So, maybe you can use the Mage.exe/MageUI.exe to fix the  Prerequisites and check all the Prerequisites in your setup projects.

    If it can not be resolved and the link be generied by itsself, than, you can submit the issue to the FeedBack website:

    https://connect.microsoft.com/VisualStudio

    If you have any questions, please feel free to tell us.

    Best Regards


    Neddy Ren [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Neddy Ren Wednesday, October 12, 2011 2:16 AM
    • Unmarked as answer by Rob K In Dev Wednesday, January 16, 2013 9:56 PM
    Tuesday, October 04, 2011 7:37 AM
  • Basically you've got this in your setup, just another Visual Studio version

    http://support.microsoft.com/kb/906766 

    and it's being complicated by mixed architecture because "bad image format" is a mixed-bitness issue, 32-bit Dll trying to load 64-bit or vice versa.  


    Phil Wilson
    Tuesday, October 04, 2011 6:01 PM