System.BadImageFormatException:64位MVC 2项目 - 带有重现错误的分步指令

发布于 2024-10-21 11:33:34 字数 4326 浏览 2 评论 0原文

我想创建一个 64 位 ASP.NET MVC 2 Web 应用程序并使用 64 位类库引用它。 但这样做我得到一个“System.BadImageFormatException”-异常

我添加的每个项目/解决方案都是.Net 4.0:

  1. 我创建一个名为“MySolution”的新空白解决方案
  2. 我向该解决方案添加一个新项目(ASP.NET MVC 2 Web应用程序) ),名为“MyMvcApplication”,没有测试单元以使其更容易(Visual studio 要求创建一个)

到目前为止,“MyMvcApplication”正在正常运行。即使将其设置为 x64。

  1. 我向解决方案(类库)添加了一个名为“MyClassLibrary”的新项目,
  2. 我将“MyMvcApplication”设置为启动项目(它应该已经是,但只是为了完整列表)做)。
  3. 我进入菜单“构建/配置管理器”,通过从“任何 CPU”复制来创建一个新平台“x64”。然后我将两个项目都设置为 x64。
  4. 现在我有调试| x64,对于“MyClassLibrary”和“MyMvcApplication”,平台为 x64,并且勾选了“构建框”。
  5. 我添加从“MyMvcApplication”到“MyClassLibrary”的引用(添加引用,进入“项目”选项卡并选择“MyClassLibrary”)。

我运行“MyMvcApplication”并收到以下错误:

Could not load file or assembly 'MyClassLibrary' or one of its dependencies.
An attempt was made to load a program with an incorrect format. 
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code. 

Exception Details: System.BadImageFormatException: Could not load file or assembly
'MyClassLibrary' or one of its dependencies. An attempt was made to load a program
with an incorrect format.

Source Error: 
An unhandled exception was generated during the execution of the current web request.
Information regarding the origin and location of the exception can be identified
using the exception stack trace below. 


Assembly Load Trace: The following information can be helpful to determine why the assembly 'MyClassLibrary' could not be loaded.

=== Pre-bind state information ===
LOG: User = Dev\Chris
LOG: DisplayName = MyClassLibrary
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: MyClassLibrary | Domain ID: 2
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///c:/Test/MySolution/MyMvcApplication/
LOG: Initial PrivatePath = c:\Test\MySolution\MyMvcApplication\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: c:\Test\MySolution\MyMvcApplication\web.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/f962adb4/1764faec/MyClassLibrary.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/f962adb4/1764faec/MyClassLibrary/MyClassLibrary.DLL.
LOG: Attempting download of new URL file:///c:/Test/MySolution/MyMvcApplication/bin/MyClassLibrary.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.

编辑:

运行“corflags c:\Test\MySolution\MyMvcApplication\bin\MyClassLibrary.DLL”,就像 Visual Studio 命令提示符中 bobbymcr 所建议的那样get:

Version   : v4.0.30319
CLR Header: 2.5
PE        : PE32+
CorFlags  : 1
ILONLY    : 1
32BIT     : 0
Signed    : 0

但我不知道如何处理这些信息:-(

编辑2:

当将所有项目切换到 x86 并运行 ASP.NET MVC 2 Web 应用程序时,我收到以下错误:

Parser Error 
Description: An error occurred during the parsing of a resource required to service this
request. Please review the following specific parse error details and modify your
source file appropriately. 

Parser Error Message: Could not load type 'MyMvcApplication.MvcApplication'.

Source Error: 

Line 1:  <%@ Application Codebehind="Global.asax.cs"
Inherits="MyMvcApplication.MvcApplication" Language="C#" %>


Source File: /global.asax    Line: 1

所以无论我是否切换到 x86 或 x64

我能做什么?

I want to create a 64bit ASP.NET MVC 2 Web Application and reference it with a 64bit class library.
But doing so I get a "System.BadImageFormatException"-Exception

Every project/Solution I add is .Net 4.0:

  1. I create a new blank solution called "MySolution"
  2. I add a new project to that solution (ASP.NET MVC 2 Web Application), called "MyMvcApplication", No Test unit to make it easier (Visual studio asks to create one)

Up to this point "MyMvcApplication" is running like it should. Even when setting it to x64.

  1. I add a new project to the soltion (Class Library), called "MyClassLibrary"
  2. I set "MyMvcApplication" as starting project (it should be already, but just for the complete list what I do).
  3. I go to the menu Build/Configuration Manager, create a new Platform "x64" by copying from "Any CPU". Then I set both projects to x64.
  4. Now I have Debug | x64 and for "MyClassLibrary" and "MyMvcApplication" the Platform to x64 and the "Build box" ticked.
  5. I add a reference from "MyMvcApplication" to "MyClassLibrary" (Add reference, got to the Projects Tab and select "MyClassLibrary").

I run the "MyMvcApplication" and get the following error:

Could not load file or assembly 'MyClassLibrary' or one of its dependencies.
An attempt was made to load a program with an incorrect format. 
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code. 

Exception Details: System.BadImageFormatException: Could not load file or assembly
'MyClassLibrary' or one of its dependencies. An attempt was made to load a program
with an incorrect format.

Source Error: 
An unhandled exception was generated during the execution of the current web request.
Information regarding the origin and location of the exception can be identified
using the exception stack trace below. 


Assembly Load Trace: The following information can be helpful to determine why the assembly 'MyClassLibrary' could not be loaded.

=== Pre-bind state information ===
LOG: User = Dev\Chris
LOG: DisplayName = MyClassLibrary
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: MyClassLibrary | Domain ID: 2
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///c:/Test/MySolution/MyMvcApplication/
LOG: Initial PrivatePath = c:\Test\MySolution\MyMvcApplication\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: c:\Test\MySolution\MyMvcApplication\web.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/f962adb4/1764faec/MyClassLibrary.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/f962adb4/1764faec/MyClassLibrary/MyClassLibrary.DLL.
LOG: Attempting download of new URL file:///c:/Test/MySolution/MyMvcApplication/bin/MyClassLibrary.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.

EDIT:

running "corflags c:\Test\MySolution\MyMvcApplication\bin\MyClassLibrary.DLL" like suggested from bobbymcr in the visual studio command prompt I get:

Version   : v4.0.30319
CLR Header: 2.5
PE        : PE32+
CorFlags  : 1
ILONLY    : 1
32BIT     : 0
Signed    : 0

But I don't know what to do with this information :-(

EDIT2:

When switching all projects to x86 and running the ASP.NET MVC 2 Web Application I get the following error:

Parser Error 
Description: An error occurred during the parsing of a resource required to service this
request. Please review the following specific parse error details and modify your
source file appropriately. 

Parser Error Message: Could not load type 'MyMvcApplication.MvcApplication'.

Source Error: 

Line 1:  <%@ Application Codebehind="Global.asax.cs"
Inherits="MyMvcApplication.MvcApplication" Language="C#" %>


Source File: /global.asax    Line: 1

So I get an error no matter if I switch to x86 or x64.

What can I do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怀中猫帐中妖 2024-10-28 11:33:34

事实上,x64 位应用程序可以加载 x86 和 x64 程序集。但 x86 应用程序只能加载 x86 程序集。 Casini(Visual Studio开发服务器)是x86应用程序,这就是为什么它不支持x64 Web应用程序运行。您必须仅在同时支持 x86 和 x64 的 IIS 上托管 x64 Web 应用程序。

另请确保类库的目标平台是“.NET Framework 4.0”,而不是“.Net 4.0 Client profile”。

如果这篇文章解决了问题,请将其标记为答案。

The fact is that x64 bit application can load both x86 and x64 assemblies. But x86 application can load ONLY x86 assemblies. Casini (Visual Studio Development Server) is x86 application, that's why it does not support x64 Web applications to run. You must host x64 Web Applications only on IIS which support both x86 and x64.

Also make sure that Target platform for your class library is ".NET Framework 4.0" but not ".Net 4.0 Client profile".

Please mark this post as Answer if it resolve the issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文