Windows > Windows Forms Forums > ClickOnce and Setup & Deployment Projects > custom action fails - cannot load file or assembly
Ask a questionAsk a question
 

Answercustom action fails - cannot load file or assembly

  • Monday, November 02, 2009 3:42 AMIB00 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    My setup project includes a C# custom action.   The custom action and setup successfully run when built and run for both the DEBUG/RELEASE configurations - Win32 platform.   They also successfully run when built and run for the DEBUG configuration - x64 platform.  However, the setup fails when run for the RELEASE configuration, x64 platform.  The error message generated is as follows:

    Error 1001. Exception occurred while initializing the installation: System.BadImageFormatException: Could not load file or assembly 'MyCustomAction, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.  An attempt was made to load a program with an incorrect form...'.    (Note: the message literally terminates with the ellipsis '...')


    The message indicates the custom action assembly could not be loaded.   To confirm I added extra logging messaging in the MyInstaller constructor and MyInstaller.Install function and the log file is in fact not created.

    Does anyone have any ideas of what might be causing the error or suggestions on how to proceed with resolving it?

    Thanks,

    Ian

    • Moved byWesley YaoMSFTTuesday, November 03, 2009 3:12 AMsetup question (From:Visual C++ General)
    •  

Answers

  • Thursday, November 05, 2009 4:33 AMIB00 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi Aland,

    My OS is Vista Home Premium.

    I finally had some time to review your references and run a few tests.    As recommended in your 2nd reference, I rebuilt the x64 deployment project from scratch and preliminary results indicate the problem no longer occurs.  I'll run more tests tomorrow and post the results.   I briefly compared the old/new deployment project file - there are differences - but I am not in a position to assess which produced the problem.

    Thanks,

    Ian
    • Marked As Answer byIB00 Sunday, November 08, 2009 7:11 PM
    •  
  • Thursday, November 05, 2009 7:50 AMAland LiMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Hi IB00,

    From my experience, the root cause of the error is that the native code in a msi file is of type 32-bit, so it cannot load a 64-bit dll. The document below provides two solutions of this issue:
    http://blogs.msdn.com/heaths/archive/2006/02/01/64-bit-managed-custom-actions-with-visual-studio.aspx

    Regards,
    Aland Li


    Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
    • Marked As Answer byIB00 Sunday, November 08, 2009 7:11 PM
    •  
  • Sunday, November 08, 2009 7:11 PMIB00 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hello Aland,

    I've rebuilt all setup projects and the problem no longer occurs.   Thanks again for you input. 

    Have a great week.

    Ian
    • Marked As Answer byIB00 Sunday, November 08, 2009 7:11 PM
    •  

All Replies

  • Wednesday, November 04, 2009 7:05 AMAland LiMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi IB00,

    Could you please let me know the version of your operation system in which the package is installed, x86 or x64?

    You can follow the document below to trouble shooting the issue:
    http://msdn.microsoft.com/en-us/library/k7137bfe(VS.80).aspx

    This is a similar thread which can give you some ideas:
    http://social.msdn.microsoft.com/Forums/en-US/winformssetup/thread/53f58f60-c355-417b-9b26-cbe50432d352

    Regards,
    Aland Li

    Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
  • Wednesday, November 04, 2009 6:35 PMPhilWilsonModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    That exception is usually from an attempt to load an incompatible assembly. For example a .NET 1.1 assembly cannot load a .NET 2.0 assembly. You might also get this message if a x86 assembly tries to load an x64 assembly. Is your C# custom action generated as MSIL, x86, x64?
    Phil Wilson
  • Thursday, November 05, 2009 4:33 AMIB00 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi Aland,

    My OS is Vista Home Premium.

    I finally had some time to review your references and run a few tests.    As recommended in your 2nd reference, I rebuilt the x64 deployment project from scratch and preliminary results indicate the problem no longer occurs.  I'll run more tests tomorrow and post the results.   I briefly compared the old/new deployment project file - there are differences - but I am not in a position to assess which produced the problem.

    Thanks,

    Ian
    • Marked As Answer byIB00 Sunday, November 08, 2009 7:11 PM
    •  
  • Thursday, November 05, 2009 4:38 AMIB00 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello Phil,

    My projects were originally created as 32 bit apps in VS2005 for .Net 2.0.   I recently imported them into VS2008.   All was well until last week when I updated them to compile for 64 bit apps.   The CA wsa generated as 'Any CPU' while the C++ projects were all generated as x64.

    Ian
  • Thursday, November 05, 2009 7:50 AMAland LiMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Hi IB00,

    From my experience, the root cause of the error is that the native code in a msi file is of type 32-bit, so it cannot load a 64-bit dll. The document below provides two solutions of this issue:
    http://blogs.msdn.com/heaths/archive/2006/02/01/64-bit-managed-custom-actions-with-visual-studio.aspx

    Regards,
    Aland Li


    Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
    • Marked As Answer byIB00 Sunday, November 08, 2009 7:11 PM
    •  
  • Sunday, November 08, 2009 7:11 PMIB00 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hello Aland,

    I've rebuilt all setup projects and the problem no longer occurs.   Thanks again for you input. 

    Have a great week.

    Ian
    • Marked As Answer byIB00 Sunday, November 08, 2009 7:11 PM
    •