Visual Studio 2010 安装项目中 CustomAction 的 System.BadImageFormatException
握紧你的枪!我确实检查了所有项目输出是否都设置为相同的处理器架构(在本例中为 x64)。他们是。那么我想做什么?
- 为 Autodesk Revit Architecture 2011 x64 编写插件
- 面向 .NET 3.5
- x64
- 创建了一个安装项目
- 创建了一个自定义操作 (
RegisterRevit2011Addin
),用于使用提供的 DLL (RevitAddInUtility.dll
) 向 Revit 注册插件- 面向 .NET 3.5
- x64
- 添加了自定义操作来设置项目、构建、安装
这是我收到的错误消息:
错误 1001。初始化安装时发生异常: System.BadImageFormatException:无法加载文件或程序集 'RegisterRevit2011,版本=1.0.0.0,文化=中性,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 进程!
我很确定前天这一切都有效,所以我有点担心我以某种方式弄乱了我的系统。有什么想法吗?
Hold your guns! I did check to see if all the project outputs are set to the same processor architecture (in this case, x64). They are. So what am I trying to do?
- Wrote a plugin for Autodesk Revit Architecture 2011 x64
- targets .NET 3.5
- x64
- Created a setup project
- Created a custom action (
RegisterRevit2011Addin
) for registering plugin with Revit using a supplied DLL (RevitAddInUtility.dll
)- targets .NET 3.5
- x64
- added custom action to setup project, build, install
This is the error message I get:
Error 1001. Exception occurred while initializing the installation:
System.BadImageFormatException: Could not load file or assembly
'RegisterRevit2011, 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 format.
Just to be sure, I created a simple console test application:
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();
}
}
}
I compiled this targeting x64 and .NET 3.5 - voilà, it works! So I can now assume the error lies somewhere in the setup project. I have set the target platform in the setup projects properties and also set the Launch condition to 3.5.
Interesting: When I check the resulting setup.exe
with dumpbin /headers
, it informs me that its a x86 process!
I'm pretty sure this all worked the day before yesterday, so I'm kinda worried I messed up my system somehow. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这听起来可能是答案: 链接
基本上,Visual Studio(至少在 2005 版中)使用 32 位填充程序运行自定义操作。构建 msi 后手动将其更改为 64 位可以解决这个问题。我现在正在调查此事。
This sounds like it could be the answer: Link
Basically, Visual Studio (at least in the 2005 edition) runs custom actions with a 32bit shim. Manually changing that to 64bit after building the msi could do the trick. I'm looking into that right now.