我想创建一个64位ASP.NET MVC 2 Web应用程序,并使用64位类库引用它。 但这样做我得到一个“System.BadImageFormatException”-Exception
我添加的每个项目/解决方案都是.Net 4.0:
到目前为止,“MyMvcApplication”正在运行。即使将其设置为x64。
我运行“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建议我得到:
Version : v4.0.30319
CLR Header: 2.5
PE : PE32+
CorFlags : 1
ILONLY : 1
32BIT : 0
Signed : 0
但我不知道如何处理这些信息: - (
EDIT2:
将所有项目切换到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,我都会收到错误。
我该怎么办?
答案 0 :(得分:4)
事实是x64位应用程序可以加载x86和x64程序集。但是x86应用程序只能加载x86程序集。 Casini(Visual Studio Development Server)是x86应用程序,这就是它不支持运行x64 Web应用程序的原因。您必须仅在支持x86和x64的IIS上托管x64 Web应用程序。
还要确保您的类库的Target平台是“.NET Framework 4.0”,而不是“.Net 4.0 Client profile”。
如果问题解决了,请将此帖标记为答案。