Asp.net mvc 4 以x64模式构建的MVC4 Web Api在执行“无法加载文件或程序集'xxx'或其依赖项”时出错

Asp.net mvc 4 以x64模式构建的MVC4 Web Api在执行“无法加载文件或程序集'xxx'或其依赖项”时出错,asp.net-mvc-4,asp.net-web-api,64-bit,Asp.net Mvc 4,Asp.net Web Api,64 Bit,我的MVC4 Web Api应用程序在任何Cpu模式下构建时工作正常。在此模式下,它正在创建32位dll。但是,当我在x64模式下构建应用程序时,执行时,它会出现以下错误: Server Error in '/' Application. -------------------------------------------------------------------------------- Could not load file or assembly 'CoreService'

我的MVC4 Web Api应用程序在任何Cpu模式下构建时工作正常。在此模式下,它正在创建32位dll。但是,当我在x64模式下构建应用程序时,执行时,它会出现以下错误:

Server Error in '/' Application.
--------------------------------------------------------------------------------


 Could not load file or assembly 'CoreService' 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 'CoreService' 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 'CoreService' could not be loaded.





=== Pre-bind state information ===
LOG: User = xxx
LOG: DisplayName = CoreService
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: CoreService | Domain ID: 3
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:///D:/StartFromScratch/src/CoreService/
LOG: Initial PrivatePath = D:\StartFromScratch\src\CoreService\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: D:\StartFromScratch\src\CoreService\web.config
LOG: Using host configuration file: C:\Users\310138409\Documents\IISExpress\config\aspnet.config
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/a4e7fe2c/87c2ced5/CoreService.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/a4e7fe2c/87c2ced5/CoreService/CoreService.DLL.
LOG: Attempting download of new URL file:///D:/StartFromScratch/src/CoreService/bin/CoreService.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.


Stack Trace: 





[BadImageFormatException: Could not load file or assembly 'CoreService' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
   System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +34
   System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +77
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +16
   System.Reflection.Assembly.Load(String assemblyString) +28
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +38

[ConfigurationErrorsException: Could not load file or assembly 'CoreService' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +752
   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +218
   System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +170
   System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +91
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath) +258
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +135
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +516

[HttpException (0x80004005): Could not load file or assembly 'CoreService' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9874840
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254



--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18055

我没有得到任何具体的解决方案。此外,我们无法在32位模式下继续,因为它正在调用64位非托管代码。提前感谢。

您应该为x64版本正确配置解决方案配置。右键单击VS中的解决方案,选择Configuration Manager在Active solution platfo下选择x64rms下拉列表并检查您的所有项目是否都使用x64平台构建。

实际上问题是因为IISExpress。每当我们从VS2012 IDE执行时,都会运行32位的IISExpress,因此它会给出错误的格式错误。因此,一旦我安装了IISExpress 8.0并完成注册表项,以确保IISExpress从VS2012执行64位;我的问题得到解决。

我在VS 2015中也遇到了这个问题。在VS 2015中,单击“工具”->“选项”。然后选择“项目和解决方案”->“Web项目”。然后选择“使用64位版本的IIS Express…”非常感谢您为我整理了最后的难题。