System.BadImageFormatException试图用不正确的格式加载程序 [英] System.BadImageFormatException An attempt was made to load a program with an incorrect format

查看:3948
本文介绍了System.BadImageFormatException试图用不正确的格式加载程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个插件,另一个程序是基于公共.NET API。通常,这些插件是通过创建一个类库DLL引用API拼装而成。然后一个命令类被从基类命令在API组件继承创建。该应用程序会被设置为引用该插件的DLL文件,然后还负责实际发射了自定义命令类,当用户请求它。

I'm writing a plug-in for another program that is based on a public .NET API. Typically these plugins are made by creating a class library DLL that references the API assembly. Then a command class is created by inheriting from a base command class in the API assembly. The application is then set to reference the plug-in DLL file, and is then also responsible for actually firing up the custom command class when the user requests it.

不过,现在我想通过系统自动执行某些code一代。codeDOM ,并希望创建一个简单的控制台应用程序,自动生成根据关类型的新类的类型与在API组件。

However, now I'm trying to automate some code generation through System.CodeDOM, and want to create a simple console application that automatically generates new Class Types based off of types with in the API assembly.

然而,当我尝试运行我的应用程序出现以下情况例外。

Yet, when I try to run my application I get the following exception.

System.BadImageFormatException是   未处理消息:无法加载文件   或组装RevitAPI,   版本= 2011.0.0.0,文化=中立,   公钥= null或它的一个   依赖性。一个试图   用不正确的加载程序   格式。

System.BadImageFormatException was unhandled Message: Could not load file or assembly 'RevitAPI, Version=2011.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.

通常我需要一个插件程序集的目标框架设置为3.5。但是现在我发现,上述错误消失,如果我把我的控制台应用程序的目标框架2.0。然而,我的控制台应用程序已经引用了我的有自己的目标框架设置为3.5其他类库。而我真的不想重写他们周围的2.0框架。

Usually I need to set the target framework of a plug-in assembly to 3.5. Yet now I've found that the error above goes away if I set the target framework of my console application to 2.0. However, my console application already references other class libraries of mine that have their target framework set to 3.5. And I'd really rather not rewrite them around the 2.0 framework.

推荐答案

这可能是32 - 64位不匹配

It's possibly a 32 - 64 bits mismatch.

如果您是在64位操作系统上运行,大会RevitAPI可以编译为32位和你的过程,64位或任何CPU。

If you're running on a 64-bit OS, the Assembly RevitAPI may be compiled as 32-bit and your process as 64-bit or "Any CPU".

或者,RevitAPI被编译为64位和流程被编译为32位或任何CPU,并在32位操作系统上运行。

Or, the RevitAPI is compiled as 64-bit and your process is compiled as 32-bit or "Any CPU" and running on a 32-bit OS.

这篇关于System.BadImageFormatException试图用不正确的格式加载程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆