【问题标题】:System.BadImageFormatException for CustomAction in Visual Studio 2010 Setup projectVisual Studio 2010 安装项目中 CustomAction 的 System.BadImageFormatException
【发布时间】:2011-03-07 05:18:37
【问题描述】:

握紧你的枪!我确实检查了是否所有项目输出都设置为相同的处理器架构(在本例中为 x64)。他们是。那我想做什么呢?

  1. 为 Autodesk Revit Architecture 2011 x64 编写了一个插件
    • 针对 .NET 3.5
    • x64
  2. 创建了一个安装项目
  3. 创建了一个自定义操作 (RegisterRevit2011Addin),用于使用提供的 DLL (RevitAddInUtility.dll) 向 Revit 注册插件
    • 针对 .NET 3.5
    • x64
  4. 为设置项目、构建、安装添加了自定义操作

这是我收到的错误消息:

错误 1001。初始化安装时发生异常: System.BadImageFormatException:无法加载文件或程序集 'RegisterRevit2011, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' 或一 其依赖项。试图加载格式不正确的程序。

为了确定,我创建了一个简单的控制台测试应用程序:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var register = new RegisterRevit2011Addin.RegisterAddinCustomAction();
            Console.WriteLine(register);
            register.Context = new System.Configuration.Install.InstallContext();
            register.Context.Parameters.Add("assemblypath",     typeof(Program).Assembly.Location);
            register.Install(new Dictionary<string, string>());
            Console.ReadLine();
        }
    }
}

我针对 x64 和 .NET 3.5 编译了这个 - 瞧,它有效!所以我现在可以假设错误出在安装项目的某个地方。我已经在设置项目属性中设置了目标平台,并将启动条件设置为 3.5。

有趣:当我用dumpbin /headers 检查生成的setup.exe 时,它告诉我它是一个x86 进程!

我很确定这一切都在前天工作,所以我有点担心我以某种方式搞砸了我的系统。有什么想法吗?

【问题讨论】:

    标签: .net-3.5 visual-studio-2010 64-bit setup-project


    【解决方案1】:

    这听起来可能是答案:http://blogs.msdn.com/b/heaths/archive/2006/02/01/64-bit-managed-custom-actions-with-visual-studio.aspx

    基本上,Visual Studio(至少在 2005 版中)使用 32 位 shim 运行自定义操作。在构建 msi 后手动将其更改为 64 位可以解决问题。我现在正在调查。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-14
      • 1970-01-01
      • 2012-01-25
      • 2011-02-15
      相关资源
      最近更新 更多