【问题标题】:Could not load file or assembly - asp.net mvc app无法加载文件或程序集 - asp.net mvc app
【发布时间】:2016-02-04 02:34:36
【问题描述】:

尝试使用 Visual Studio 2010 处理 mvc 3 应用程序。该应用程序编译良好。但是,在运行时失败。

Could not load file or assembly 'InnVue.BOA.RoomControl' 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 'InnVue.BOA.RoomControl' 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.

程序集加载跟踪:以下信息有助于确定程序集“InnVue.BOA.RoomControl”无法加载的原因。

=== Pre-bind state information ===
LOG: DisplayName = InnVue.BOA.RoomControl
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: InnVue.BOA.RoomControl | Domain ID: 10
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:/Users/KHAN/Documents/GitHub/innvue/InnVue.InnDesk/InnVue.InnDesk/InnVue.InnDesk/
LOG: Initial PrivatePath = C:\Users\KHAN\Documents\GitHub\innvue\InnVue.InnDesk\InnVue.InnDesk\InnVue.InnDesk\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\KHAN\Documents\GitHub\innvue\InnVue.InnDesk\InnVue.InnDesk\InnVue.InnDesk\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:/Users/KHAN/AppData/Local/Temp/Temporary ASP.NET Files/root/41f4bb6c/382c05ac/InnVue.BOA.RoomControl.DLL.
LOG: Attempting download of new URL file:///C:/Users/KHAN/AppData/Local/Temp/Temporary ASP.NET Files/root/41f4bb6c/382c05ac/InnVue.BOA.RoomControl/InnVue.BOA.RoomControl.DLL.
LOG: Attempting download of new URL file:///C:/Users/KHAN/Documents/GitHub/innvue/InnVue.InnDesk/InnVue.InnDesk/InnVue.InnDesk/bin/InnVue.BOA.RoomControl.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.

堆栈跟踪是:

[BadImageFormatException: Could not load file or assembly 'InnVue.BOA.RoomControl' 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) +36
   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) +21
   System.Reflection.Assembly.Load(String assemblyString) +28
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +38

[ConfigurationErrorsException: Could not load file or assembly 'InnVue.BOA.RoomControl' 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) +738
   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +217
   System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +170
   System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +92
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +290
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +157
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +531

[HttpException (0x80004005): Could not load file or assembly 'InnVue.BOA.RoomControl' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9942412
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +90
   System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +456

我已经确认:

InnVue.BOA.RoomControl.dll 确实是 64 位 dll

InnVue.BOA.RoomControl.dll 引用的程序集也被主项目引用。

有没有什么方法可以准确地找到问题所在?堆栈跟踪中提供的信息不是很明显。

【问题讨论】:

    标签: c# asp.net asp.net-mvc asp.net-mvc-3 asp.net-mvc-4


    【解决方案1】:

    测试你的程序集引用的简单测试,如果它已被正确添加到您的项目中,copy local 是真的。 尝试将 release 构建部署到您的 本地 IIS 并尝试运行您的项目。您的应用程序可能由于缺少程序集而无法运行,请在返回之前继续修复它并打包您的 Web 应用程序以在 Azure 上对其进行测试。

    另外,我使用程序集绑定日志查看器,它可以准确地告诉您 GAC 或您的 bin 目录中不存在的缺失程序集是什么。

    下载链接:https://msdn.microsoft.com/en-us/library/e74a18c4(v=vs.110).aspx

    希望这会有所帮助!

    【讨论】:

    • 有趣的是,该项目在本地 IIS 中运行良好,但调试仍然无法正常工作。这有什么线索吗?
    • 删除您的 IIS 部署,包括 bin 目录,推送新的 DEBUG 构建,附加 w3wp 进程并运行应用程序。您将能够调试应用程序。您必须确保附加正确的流程,这是关键。否则您将无法针对 IIS 进行调试。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-28
    • 1970-01-01
    • 2012-11-11
    • 2016-08-16
    • 2019-09-06
    相关资源
    最近更新 更多